Using $ apply () with a component

I am trying to use $apply()with angular 1.5 component and I get an error that is self.$applynot a function.

viewTest.controller('viewTest', function ($location) {
    var self = this;
    self.$onInit = function (location) {
    self.$apply()
    }
});
+4
source share
1 answer

use $scopeinstead self. Since $applyit is an angular js $ scope function, so you cannot call it throughthis

viewTest.controller('viewTest', function ($scope,$location) {
    var self = this;
    self.$onInit = function (location) {
    $scope.$apply()
    }
});
+6
source

Source: https://habr.com/ru/post/1670218/


All Articles