我能够从外部JS方法调用Angular JS控制器方法。但是对数据的任何更改都没有反映在数据绑定中......
enter code here
applicantInfo.controller('testController', function($scope, $http,$timeout) {
$http.get("XXX").success(function (response) {$scope.data-bding= response;});
/* This is fine*/
/* below is called from outside controller*/
$scope.loadFocusData = function () {
$http.get(XXXX).success(function(response) {
$timeout(function() {
alert(JSON.stringify(response)); // I can see the JSON response printing
$scope.$apply(function(){
this.data-bdingin= response; // does not happen
});
});
});
};
JS调用Controller方法
var scope = angular.element('XXXX').scope();
scope.$apply(function() {
scope.XXXX = XXXX;
scope.loadFocusData();
});
非常感谢任何帮助..
答案 0 :(得分:0)
看起来......我只需要使用"来定义使用父范围。范围:false",因此数据可以跨越并转换:true ...所以外部世界可以更新数据。还有其他选择,根据您的尝试,这可能会产生副作用。