Sherman S Sherman S - 1 year ago 72
AngularJS Question

How to call $scope.$apply() using "controller as" syntax

I am trying to limit my use of

in my controllers as much as possible and replace it with the
Controller as

My current problem is that i'm not sure how to call
in my controller without using

Edit: I am using TypeScript 1.4 in conjunction with angular

I have this function

setWordLists() {
this.fetchInProgress = true;
var campaignId = this.campaignFactory.currentId();
var videoId = this.videoFactory.currentId();

if (!campaignId || !videoId) {

this.wordsToTrackFactory.doGetWordsToTrackModel(campaignId, videoId)
.then((response) => {
this.fetchInProgress = false;
this.wordList = (response) ? : [];
this.notUsedWordList = (response) ? : [];

being called from

$scope.$on("video-switch",() => {

And it's (the arrays
is not being updated in my view:

<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 class="col-md-2">
<span aria-hidden="true" class="glyphicon-remove glyphicon" ng-click="wordTrack.removeWord(words.Word)"></span>

Along the same lines of
, is there another way of calling
Controller as


Answer Source

To answer the question at hand here, you can use $scope() methods in a controller when using the controller-as syntax, as long as you pass $scope as a parameter to the function. However, one of the main benefits of using the controller-as syntax is not using $scope, which creates a quandary.

As was discussed in the comments, a new question will be formulated by the poster to review the specific code requiring $scope in the first place, with some recommendations for re-structuring if possible.