【问题标题】:Component not working in angular and also doesn't show any error组件不能以角度工作,也没有显示任何错误
【发布时间】:2018-06-08 18:51:35
【问题描述】:

无法使用组件呈现 html 文件。它没有显示任何错误,并且组件内部的控制器也没有被调用。

(function(angular) {
  'use strict';
  angular.module('graphApp', []).component('graphDetail', {
    templateUrl: './graphDetail.html',
    controller: function() {
      console.log('I am in component');
    },
    bindings: {
      options: '='
    }
  });
})(window.angular);

【问题讨论】:

  • 你在哪里使用这个组件?请提供所有相关详细信息。
  • 我不确定为什么这会导致问题,因为您的代码对我来说看起来是正确的。检查浏览器控制台是否有任何错误。
  • 它没有显示任何错误
  • 可能有点傻,但是你确定你的这个代码的js被包含进去了吗?

标签: javascript angularjs angular-components


【解决方案1】:

在这个 DEMO 中运行良好:

(function(angular) {
  'use strict';
  angular.module('graphApp', []).component('graphDetail', {
    template: `<fieldset>graph-detail</fieldset>`,
    controller: function() {
      console.log('I am in component');
    },
    bindings: {
      options: '='
    }
  });
})(window.angular);
<script src="//unpkg.com/angular/angular.js"></script>
<div ng-app="graphApp">
  <graph-detail options></graph-detail>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 1970-01-01
    • 1970-01-01
    • 2013-05-21
    • 2023-02-08
    • 1970-01-01
    • 2021-03-22
    相关资源
    最近更新 更多