AngularJS 1.5+ Components do not support Watchers, what is the work around?

前端 未结 7 1232
广开言路
广开言路 2020-11-22 09:23

I\'ve been upgrading my custom directives to the new component architecture. I\'ve read that components do not support watchers. Is this correct? If so how do you detect cha

7条回答
  •  萌比男神i
    2020-11-22 09:46

    I'm late. But it can help to another people.

    app.component("headerComponent", {
        templateUrl: "templates/header/view.html",
        controller: ["$rootScope", function ($rootScope) {
            let $ctrl = this;
            $rootScope.$watch(() => {
                return $ctrl.val;
            }, function (newVal, oldVal) {
                // do something
            });
        }]
    });
    

提交回复
热议问题