Third Party Asynchronous Callback in AngularJS 1.5 Component

Before AngularJS 1.5 in directives or views would check if the change would be replaced by angular (using the $ digest loop) when the change was released from a third-party asynchronous callback, it would run your code in $scope.$apply().

With components, as I understand it, the idea is to get rid of $scopeand just bind the template to the component controller. I am trying to move on to writing components instead of representations, not relying on $ scope. Let's say I have the following code:

function CompController(TPApi) {
    let self = this;
    this.endCallback = false;
    TPApi.call(data, () => this.endCallback = true );
}

angular.module('app',  []).component('myComp', {
    controller: CompController,
    template: '<div><span ng-show="$ctrl.endCallback">Callback Called</span></div>'
})

, ng-show , $scope. $apply() , ng-show, $digest . , $scope $apply, $scope .

, , TPApi $q, , $digest . , - API Promise $q?

$digest angular 1 - $scope $digest?

+4
1

API, angular . $scope, $timeout ( )

function CompController(TPApi) {
    let self = this;
    this.endCallback = false;
    TPApi.call(data, () => $timeout(() => this.endCallback = true, 0));
}
0

All Articles