0

I am reading angular guide Directive section:https://docs.angularjs.org/guide/directive

When reading following code, I saw the string, 'close', appears in directive scope, which is different to something like customInfo I saw before. And I cannot find documents address this in detail. Presumably, it is to define a function for ng-click to call. However, I hope I could find more information about this.

.directive('myDialog', function() {
  return {
    restrict: 'E',
    transclude: true,
    scope: {
      'close': '&onClose'
    },
    templateUrl: 'my-dialog-close.html'
  };
});

BTW, here is the one not using string:

.directive('myCustomer', function() {
  return {
    restrict: 'E',
    scope: {
      customerInfo: '=info'
    },
    templateUrl: 'my-customer-iso.html'
  };
});
Rob Lao
  • 1,526
  • 4
  • 14
  • 38
  • 1
    Possible duplicate of [What is the difference between object keys with quotes and without quotes?](http://stackoverflow.com/questions/4348478/what-is-the-difference-between-object-keys-with-quotes-and-without-quotes) – BentoumiTech May 12 '16 at 09:55

1 Answers1

0

It's the same: in javascript you can define object keys without quotes, if they don't contain special chars, or with quotes. You can also access them with brackets (scope['close']) or dot (if no special chars, scope.close)

maxdec
  • 5,707
  • 2
  • 30
  • 35