角度指令作用域中的字符串键和非字符串键有什么区别?



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

在阅读以下代码时,我看到字符串"close"出现在指令范围中,这与我以前看到的customInfo不同。我找不到详细说明这一点的文件。据推测,这是为了定义一个函数,让ng点击调用。然而,我希望我能找到更多关于这方面的信息。

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

顺便说一句,这是一个不使用字符串的:

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

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

最新更新