run method after lifecycle angular

100 views Asked by At

i want run method after lifecycle angular for example : for change font used as cufon . i want after click on button and call ng-click="addHandler()" statement Cufon.replace('h1', { onBeforeReplace: Bifon.convert }); called? do you Solution? tanks

Here is my code :

after ngclick impossible for example:

$scope.text = "این یک تست است";
        $scope.AddHandler = function () {
            $scope.text = "تست تست";
            Cufon.replace('h1', { onBeforeReplace: Bifon.convert });

        };


        <h1> {{text}}</h1>
        <button ng-click="AddHandler()">Add</button>
1

There are 1 answers

0
benek On

You can do it with a directive :

angular.module('myApp', [])
  .directive('replaceStyle', function() {
    return function(scope, element, attrs) {
        element.ready(function(){
          element.html(element.html().replace('h1', { onBeforeReplace: Bifon.convert }))
        })
    };
});

And in your markup :

<div replaceStyle>
   {{your_content}}
<div>

To change the style with a button, just put the code of the directive inside a function published in the scope (scope.changeStyle....)