Angular version 1.5.8。AngularJS定義組件的控制器
這裏被簡化代碼我的HTML頁面:
<body>
<div ng-app="identicaApp">
<div id="navbar_wrapper">
<navbar-component></navbar-component>
</div>
<div id="register_player_wrapper">
<register-player></register-player>
</div>
</div>
<script src="/static/angular/identica/identica.js"></script>
<script src="/static/angular/identica/common.js"></script>
<script src="/static/angular/identica/navbar/navbar.module.js"></script>
<script src="/static/angular/identica/navbar/navbar.component.js"></script>
<script src="/static/angular/identica/registration/register_player/register-player.module.js"></script>
<script src="/static/angular/identica/registration/register_player/register-player.component.js"></script>
</body>
NavBar是正確加載,但註冊玩家分量不加載所有,沒有任何錯誤。下面是寄存器player.component.js的代碼:
angular.module('identicaApp.registration.player', ['identicaApp.common'])
.component('registerPlayer', {
templateUrl: '/static/angular/identica/registration/register_player/register_player.html',
controller: ['$resource', '$http', 'geolocationProvider', function RegisterPlayerController($resource, $http, geolocationProvider) {
// logic here
}]
});
我試圖限定內部
<div id="navbar_wrapper" ng-controller="RegisterPlayerController">
或
<navbar-component ng-controller="RegisterPlayerController"></navbar-component>
但在這種情況下,錯誤的角度落在控制器Argument 'RegisterPlayerController' is not a function, got undefined
。我會很感激任何幫助。
你爲什麼試圖通過'ng-controller'添加'component's'控制器?我的意思是爲了什麼?爲什麼你需要在外面添加它? – Kindzoku
@Kindzoku只是想做點什麼讓它工作 – Compadre
使用'controllerAs'和在'register_player.html'裏面使用它 – taguenizy