如何解决如何使用“ controller as”语法调用$ scope$ apply
为了回答此处的问题$scope()
,只要$scope
将参数作为参数传递给函数,就可以在使用controller-
as语法时在控制器中使用方法。但是,使用controller-as语法的主要好处之一是没有使用$scope
,这会产生一个难题。
正如评论中所讨论的那样,发布者将提出一个新问题,以首先审查所需的特定代码$scope
,并在可能的情况下提出一些重组建议。
解决方法
我试图限制我$scope
在控制器中的使用,并用Controller as
语法替换它。
我当前的问题是我不确定如何$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>
沿着相同的路线$apply
,有没有调用的另一种方法$scope.$on
使用Controller as
?
谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。