角度指令范围中字符串和非字符串键之间的区别是什么?

时间:2016-05-12 09:36:08

标签: angularjs angularjs-directive

我正在阅读角度指南指令部分:https://docs.angularjs.org/guide/directive

当阅读下面的代码时,我看到字符串'close'出现在指令范围内,这与我之前看到的customInfo不同。我找不到文件详细解决这个问题。据推测,它是为ng-click调用定义一个函数。但是,我希望我能找到更多相关信息。

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

BTW,这是不使用字符串的那个:

.directive('myCustomer', function() {
  return {
    restrict: 'E',
    scope: {
      customerInfo: '=info'
    },
    templateUrl: 'my-customer-iso.html'
  };
});

1 个答案:

答案 0 :(得分:0)

它是相同的:在javascript中,您可以定义没有引号的对象键,如果它们不包含特殊字符或带引号。 您也可以使用括号(scope['close'])或点(如果没有特殊字符,scope.close

来访问它们