尽管接线正确,控制器仍未定义角度

时间:2014-12-02 18:40:47

标签: angularjs

我收到以下错误:

  Error: [ng:areq] http://errors.angularjs.org/1.3.2/ng/areq?p0=NavigationController&p1=not%20a%20function%2C%20got%20undefined
at Error (native)
at http://localhost:59838/bundles/angular?v=eGVVmShKFZLix9VnkpB8psikEOhD8WAVwpsLlHRCbyE1:6:416
at Nb (http://localhost:59838/bundles/angular?v=eGVVmShKFZLix9VnkpB8psikEOhD8WAVwpsLlHRCbyE1:19:417)
at ob (http://localhost:59838/bundles/angular?v=eGVVmShKFZLix9VnkpB8psikEOhD8WAVwpsLlHRCbyE1:20:1)
at http://localhost:59838/bundles/angular?v=eGVVmShKFZLix9VnkpB8psikEOhD8WAVwpsLlHRCbyE1:75:177
at http://localhost:59838/bundles/angular?v=eGVVmShKFZLix9VnkpB8psikEOhD8WAVwpsLlHRCbyE1:57:112
at r (http://localhost:59838/bundles/angular?v=eGVVmShKFZLix9VnkpB8psikEOhD8WAVwpsLlHRCbyE1:7:408)
at I (http://localhost:59838/bundles/angular?v=eGVVmShKFZLix9VnkpB8psikEOhD8WAVwpsLlHRCbyE1:56:496)
at g (http://localhost:59838/bundles/angular?v=eGVVmShKFZLix9VnkpB8psikEOhD8WAVwpsLlHRCbyE1:51:299)
at g (http://localhost:59838/bundles/angular?v=eGVVmShKFZLix9VnkpB8psikEOhD8WAVwpsLlHRCbyE1:51:316)

这是我的app.js:

(function () {
    'use strict';
    var app = angular.module('app', ['navigation']);
})();

这是导航控制器:

function() {
var navigation = angular.module('navigation', []);
    navigation.controller('NavigationController', function () {
    this.tabs = [
        { title: 'First Tab', content: 'Controllers\FirstTab' },
    ];
    });
})();

以下是呈现这一点的部分视图:(目前尚未到达此处)

 <div ng-controller="NavigationController as nav">
    <ul class="nav nav-pills">
        <li ng-repeat="tab in nav.tabs">{{tab.title}}</li>
    </ul>
</div>

对我来说(有角度的菜鸟)一切都很好看。我错过了什么?

更新:

Fiddle

1 个答案:

答案 0 :(得分:1)

您可以查看:

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

var app = angular.module('myApp', ['navigation']);


navigation.controller('NavigationController', function ($scope) {
    $scope.tabs = [
        { title: 'First Tab', content: 'Controllers\FirstTab' },
        { title: 'Second Tab', content: 'Controllers\SecondTab' },
        { title: 'Third Tab', content: 'Controllers\ThirdTab' },
        { title: 'Fourth Tab', content: 'Controllers\FourthTab' },
        { title: 'Fifth Tab', content: 'Controllers\FifthTab' },
        { title: 'Sixth Tab', content: 'Controllers\SixthTab' },
        { title: 'Seventh Tab', content: 'Controllers\SeventhTab' }
    ];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
    <div ng-controller="NavigationController as nav">
        <div ng-repeat="tab in tabs">
            <b> {{ tab.title}} </b> {{ tab.content}}
        </div>
    </div>
</div>