AngularJS で意図的に更新する
app.controller("MainCtrl", function ($scope) { uri = '...'; $.get(uri, function(data){ $scope.result = data.responseText; }); });
上記のようなコード書いていたのだけれど、これだと {{ result }}
が更新されなかった。
($http 使えというのは置いておく。
解決
次のように $scope.$apply()
を呼び出して意図的に更新したらうまく動作した。
app.controller("MainCtrl", function ($scope) { uri = '...'; $.get(uri, function(data){ $scope.result = data.responseText; // 更新内容が反映される $scope.$apply(); }); });