AngularJS组件绑定在缩小时未定义

时间:2017-01-12 10:40:03

标签: javascript angularjs recursion binding components

我的应用有问题。当我使用grunt serve构建它时,一切都运行正常,但是当我尝试将它构建为dist时,似乎我的组件绑定在某种程度上失败了。代码看起来像这样:

angular.module('jsonParserApp')
.component('leafTemplate', {
  templateUrl: 'views/itemList.html',
  bindings: {
    readonly: '<',
    //other bindings (works properly)
  },
  controller: ['$scope', 'copiedValue', function($scope, copiedValue) {
    //code
    this.$onChanges = function(changesObj) {
      console.log('onChanges', changesObj);
    //code
    };
    //code
  }]
});

然后当我检查什么是值时     ctrl.readonlyconsole.log中它返回

{
  "readonly": {
    "currentValue": true,
    "previousValue": UNINITIALIZED_VALUE
  } 
}

然而,当我查看grunt&#39; s中的记录值时,它会返回

{
  "readonly": {
    "currentValue": undefined,
    "previousValue": UNINITIALIZED_VALUE
  } 
}

重要的是要提到这些组件是递归构建的。 html中的代码看起来或多或少是这样的:(第一个代码示例将readonly初始化为true或false,然后它应该传播到子元素)

<ul ng-show="main.toggleInputTree" class="overflow-auto" flex>
  <li ng-repeat="(key, value) in main.inputJson">
    <leaf-template k="key" t="main.inputJson" i="{{$index}}" readonly="true" parent="$"></leaf-template>
  </li>
</ul>

(第二个代码示例,应该从它的父母传播 - grunt serve工作,grunt&#39; s dist - not)

<ul ng-show="ctrl.displayChildren" ng-if="!ctrl.isString(ctrl.t, ctrl.k)">
  <li ng-repeat="(key, value) in ctrl.t[ctrl.k]">
    <leaf-template k="key" t="ctrl.t[ctrl.k]" i="{{$index}}" readonly="ctrl.readonly" parent="{{ctrl.parent + '.' + ctrl.k}}"></leaf-template>
  </li>
</ul>

问题是什么,为什么值不会在minified / uglified版本上传播?

@UPDATE

我尝试调试它,我发现了一些非常有趣的东西。在构建之前,html看起来像这样:

<leaf-template k="key" t="ctrl.t[ctrl.k]" i="{{$index}}" readonly="ctrl.readonly" parent="{{ctrl.parent + '.' + ctrl.k}}"></leaf-template>

在dist版本中,$ templateCache保持html,看起来像这样

<leaf-template k="key" t="main.inputJson" i="{{$index}}" readonly parent="$"></leaf-template>

由于某些原因,readonly="ctrl.readonly"被裁减为readonly

1 个答案:

答案 0 :(得分:1)

将名称从readonly更改为其他任何帮助...实际上readonly是HTML输入的属性,因此uglify将readonly="ctrl.readonly"解析为readonly

相关问题