这很可能很简单,但仍然如此。我在我的控制器中有一个http调用,我加载了一个json文件。我想根据结果更新我的html中的变量。它显然更新JS中的变量(console.log),但不是在html中。 有没有办法使用$ apply的结果或类似的?还有什么可以使用的? 这里有一个(not) working plnkr更新角度为http请求的回调变量
JS:
function SomeController($http){
this.someValue = 'initial';
$http.get('test.json').then(function (data) {
this.someValue="changed";
console.log("get request "+this.someValue);
});
}
app.controller('someController', SomeController);
HTML:
<div ng-controller="someController as some">
<p>{{some.someValue}}</p>
</div>