這很可能很簡單,但仍然如此。我在我的控制器中有一個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>