AngularJS: Fire an event immediately after $scope.$digest

前端 未结 3 1353
庸人自扰
庸人自扰 2021-02-04 06:58

In my AngularJS app, there\'s several points at which I want to wait for a $scope to be processed into the DOM, and then run some code on it, like a jquery fadeIn, for example.<

3条回答
  •  孤独总比滥情好
    2021-02-04 07:12

    Alternatively, this example will work the same way as an AngularJS built-in ng-show directive, except it will fade-in or fade-out based on AngularJS condition:

  • ... myApp.directive('ngDsFade', function () { return function(scope, element, attrs) { element.css('display', 'none'); scope.$watch(attrs.ngDsFade, function(value) { if (value) { element.fadeIn(200); } else { element.fadeOut(100); } }); }; });
  • Source: http://www.codeproject.com/Articles/464939/Angular-JS-Using-Directives-to-Create-Custom-Attri

提交回复
热议问题