ham*_*zox 5 javascript angularjs
更新我的名单时,我是有问题的NG-重复的观点和$范围.$适用前来救援.我关注观察者.使用$ scope.$ apply()经常是一个好习惯吗?由于我在应用程序中有很多视图,必须在按钮单击时立即更新.
PS:任何替代方案都表示赞赏.
我的应用程序的示例JS代码:
function onRefreshList() {
vm.showLoader = true;
GetDataService.getVotes(someParams).then(function(res) {
if (res){
vm.showLoader = false;
vm.voteList = res; //voteList will be updated on click of Refresh list
$scope.$apply(); //working fine with this }
}).catch(function (res) {
vm.showLoader = false;
console.log("There was an error will loading votes");
})
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<div ng-show="showLoader">
<ion-spinner icon="android" class="spinner-assertive"></ion-spinner>
</div>
<div ng-show="!showLoader" ng-repeat="vote in votesCtrl.voteList">
{{vote}}
</div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
174 次 |
| 最近记录: |