AngularJS $ parameter not working

I am trying to understand $ parse based on the documentation . But I had problems with my test code. Am I using $ parse service correctly?

The main part of the code:

app.directive('try', function($parse) {
  return {
    restrict: 'E',
    scope: {
      sayHello: "&hello"
    },
    transclude: true,
    template: "<div style='background:gray;color:white'>Hello I am try: <span ng-transclude></span><div>",
    link: function($scope, $elem, $attr) {
      var getter = $parse($attr.sayHello);
      // var setter = getter.assign;
      $elem.on('click', function() {
        getter($scope);
        $scope.$apply();
      });
    }
  };
});

See my code at: http://plnkr.co/edit/lwV5sHGoCf2HtQa3DaVI

+4
source share
2 answers

I did not use the $ parse method, but this code gives what you are looking for:

http://plnkr.co/edit/AVvxLR4RcmWhLo8eqYyd?p=preview

+1
source

As far as I can tell, the service is $parseintended to be used outside of the allocation area.

, , 'sayHello': '&', . $parse , getter($scope), .

: : getter($scope.$parent) . , $scope getter, $parse. , $scope.$parent.

, , . scope: { ... } , , . , , , dragenter ( Angular). Shai , , , $parse.

scope : http://plnkr.co/edit/6jIjc8lAK9yjYnwDuHYZ

-1

Source: https://habr.com/ru/post/1542750/


All Articles