我试图尽可能地限制我在控制器中使用$ scope,并将其替换为Controller作为语法。
原文链接:https://www.f2er.com/angularjs/144118.html我当前的问题是,我不知道如何调用$ scope。$ apply()在我的控制器中,而不使用$ scope。
编辑:我正在使用TypeScript 1.4与角度
我有这个功能
setWordLists() { this.fetchInProgress = true; var campaignId = this.campaignFactory.currentId(); var videoId = this.videoFactory.currentId(); if (!campaignId || !videoId) { return; } this.wordsToTrackFactory.doGetWordsToTrackModel(campaignId,videoId) .then((response) => { this.fetchInProgress = false; this.wordList = (response) ? response.data.WordList : []; this.notUsedWordList = (response) ? response.data.NotUsedWords : []; }); }
被叫来
$scope.$on("video-switch",() => { this.setWordLists(); });
它是(数组wordList而notUsedWordList)
在我看来没有更新:
<div class="wordListWellWrapper row" ng-repeat="words in wordTrack.wordList"> <div class="col-md-5 wordListWell form-control" ng-class="(words.IsPositive)? 'posWordWell': 'negWordWell' "> <strong class="wordListWord">{{words.Word}}</strong> <div class="wordListIcon"> <div class="whiteFaceIcon" ng-class="(words.IsPositive)? 'happyWhiteIcon': 'sadWhiteIcon' "></div> </div> </div> <div class="col-md-2"> <span aria-hidden="true" class="glyphicon-remove glyphicon" ng-click="wordTrack.removeWord(words.Word)"></span> </div> </div>
按照同样的条件申请,是否有另一种方式调用$ scope。$ on使用Controller作为?
谢谢!