AngularJS模板不会从控制器中提取数据

时间:2016-12-18 19:49:45

标签: javascript html angularjs

* Angular版本1

在我的index.html上:

(include js files with <script>)
...
<statbox></statbox>
...

在js / app.js上

var app = angular.module('buttonMasher', ['dashboard']);

在js / dashboard / dashboard.module.js

var dashboardModule = angular.module('dashboard', []);

在js / dashboard / statbox.component.js

angular.
    module('dashboard').
    component('statbox', {
      templateUrl: 'templates/dashboard/statbox.template.html',
      controller: this.statbox = [
                                {
                                    "key1" : "value1",
                                    "key2" : "value2"
                                }
                         ]
       });

在模板/仪表板/ statbox.template.html

<div id="statbox">
<tr ng-repeat="(key, value) in statbox">
    <td>{{key}}</td> <td> {{value}}</td>
</tr>

如果我加载index.html,我只会看到{{key}} {{value}}。为了查看key1 value1和key2 value2,我需要做什么?

1 个答案:

答案 0 :(得分:0)

控制器应该是一个功能(功劳归于@ndoes) 另外,在html模板中使用$ ctrl而不是this。