先上代码吧。
var myapp = angular.module('myapp', []); myapp.service('instance', function () { return {}; }); myapp.controller('AController', ['$scope', '$http', 'instance', function ($scope, $http, instance) { var promise = $http({ method: 'POST', url: 'XXX', data: {a:a} }); promise.success(function (data, status, headers, config) { instance.callback(data.data); }); }]); myapp.controller('BController', ['$scope', 'instance', function ($scope, instance) {
instance.callback = function(dataList){
$scope.DataList = dataList;
} }]);
<table ng-controller="BController"> <tr> <th>1</th> <th>1</th> </tr> <tr ng-repeat="item in DataList"> <td>{{item.Id}}</td> <td>{{item.Name}}</td> </tr> </table>
问题来了,为什么回调函数执行、将数据赋值给BController的$scope属性后,View没有变化呢?
我要做的就是AController接收到响应后能让BController里面的Table马上发生变化。