How to wait for binding in Angular 1.5 component (without $scope.$watch)

后端 未结 4 928
广开言路
广开言路 2021-01-31 08:24

I\'m writing an Angular 1.5 directive and I\'m running into an obnoxious issue with trying to manipulate bound data before it exists.

Here\'s my code:

ap         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-31 09:11

    You could use the new lifecycle hooks, specifically $onChanges, to detect the first change of a binding by calling the isFirstChange method. Read more about this here.

    Here's an example:

提交回复
热议问题