Wait for data in controller before link function is run in AngularJS directive

前端 未结 2 699
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-31 17:17

How can I ensure that data from a controller has been loaded in a directive before the link function is run?

Using psuedo-code, I could have:



        
2条回答
  •  忘了有多久
    2021-01-31 17:45

    app.directive('MyDirective', function() {
        return {
            controller: function() {
                this.$postLink = function() {
                    // here will run after the link function and also after the binding came in
                };
            },
            controllerAs: 'vm'
        };
    });
    

    check out the angular 1.5 Components have a well-defined lifecycle and it works on directives to

提交回复
热议问题