Angularjs directive: Isolated scope and attrs

前端 未结 2 899
北海茫月
北海茫月 2020-12-04 06:43

Please see the example here

foodMeApp.directive(\'fmRating\', function() {
  return {
    restrict: \'E\',
    scope: {
      symbol: \'@\',
      max: \'@\         


        
2条回答
  •  遥遥无期
    2020-12-04 07:26

    Using attrs you are able to access the attributes defined in your html tag like

    
    

    So in this case you will have access to the symbol and readonly attributes. Every attribute you define in your custom directive will be available to the attrs variable.

    The block:

    attrs.max = scope.max = parseInt(scope.max || 5, 10);
    

    Will parse and assign the current scope.max value or 5, if non existent, to the scope.max and attrs.max. This way, after the assignment you can read from attrs.max. Before that the attrs.max property in undefined.

    Inspecting the fmRating.js source i don't know why/where/when this piece of code is being used.

提交回复
热议问题