发表于: 2017-01-15 23:51:27

1 1333


今天完成的事情:

#使用服务获取到了数据

明天计划的事情:

#继续完成服务调用数据的功能

遇到的问题:

#在服务里面获取得到数据,在控制器里面无法取出来使用(详情见注释代码),不知道为什么,后来找了很久的资料后,使用了
myApp.service('nukeService', function($rootScope,$http) {
    //$http.get("/student-ajax/students")
    //    .then(function(res){
    //        if (res.data.code == 200) {
    //            return res.data.data;
    //        } else {
    //            alert("数据获取失败,请刷新");
    //        }
    //    })
    var nukeService = {};
    nukeService.data = {};
    //Gets the list of nuclear weapons
    nukeService.getNukes = function() {
        $http.get('/student-ajax/students')
            .success(function(data) {
                nukeService.data.nukes = data.data;
            });
        return nukeService.data;
    };
    return nukeService;
});
 
myApp.controller('demoCtrl', function($scope,$http,nukeService) {
    $scope.names = nukeService.getNukes();
    console.log($scope.names);
});
在控制台能看见打印出来的对象,但是在html里面repeat不出来,真是一个让人欲哭无泪的事情啊。
<tr ng-repeat="x in names">
                                    <td >
                                {{ x.id}}
                                </td>
                                <td>
                                {{ x.name}}
                                </td>
                                <td>
                                {{ x.type }}
                                </td>
                                <td>
                                 {{x.level}}
                                </td>
                                <td>
                                    {{ x.joinTime}}
                                </td>
                                <td>
                                    <button type="button"  class="btn btn-primary u-list1 text-right" ng-click="remove($index)">删除</button>
                                    <button type="button" class="btn btn-primary u-list1 text-right" >编辑</button>
                                </td>
                                </tr>

收获:

#数据获取成功

#师弟分享了关于$state  $watch $scope $rootScope 分别是什么,其中$watch是谁,干什么。$scope 变量$rootScope全局变量$state路由中的一项服务



返回列表 返回列表
评论

    分享到