Angularjs, Directive, ampersand

I am learning AngularJS, and today I come across a strange case. So this is the code: Plunker

And there are some things that I just can’t explain:

  • If you can see the value console.log(scope.done)from the Plunker link above, this value function (a){return l(e,a)}, this value looks like a version of a compressed function . After playing with the code a bit, I found that the above function returns ( and I assume ) a call expression, logChore(chore)we go to the completed attribute done="logChore(chore)", therefore, when function (a){return l(e,a)}we perform the function logChore(chore) ?
  • Another thing is why the use of site maps done({chore:chore}) , I understand that the value of the chore will be inserted into the parameter of the same name logChore(chore), but why can not I do it: done(chore).

Well, if someone can help me understand all this, I will be very grateful, thank you all and have a nice day.

+3
source share
1 answer

I am learning AngularJS, and today I come across a strange case .

I don’t understand why this is strange, just how angular.js works, and it's great!

this value looks like a version of a compressed function ...

You are right, if I run Console.log(scope.done)with non-minified code, I get:

function (locals) {
  return parentGet(scope, locals);
} 

compile.js:

case '&':
  parentGet = $parse(attrs[attrName]);
  isolateScope[scopeName] = function(locals) {
    return parentGet(scope, locals);
  };

, scope: { done : "&"}, angular $parse , .

, : done="logChore(chore)" , chore.

angular , ng-click="do($event)", $event, ?

Angular , locals , .

: done (chore)?

, angular & , . , , :

  • done = "logChore(chore); x = 1"
  • done = "logChore(otherVar, chore)"
  • done = "isLogged || logChore(chore)"
  • done = "logChore(chore + 1)"

, , , , , , .

, , locals, , .

+7

All Articles