次の Angular 1.5 コンポーネントがあります。
(function () {
'use strict';
angular
.module('EmployeeInformation')
.controller('EmployeeDetailCtrl', EmployeeDetailCtrl)
.component('employeeDetail', EmployeeDetail);
var EmployeeDetail = {
templateUrl: '../views/components/employeeDetail.html',
controller: 'EmployeeDetailCtrl as empdetail',
bindings: {
employee: '<'
}
};
function EmployeeDetailCtrl() { }
})();
Angular のサイトの例に基づいて、私には正しいようです。ただし、ページにファイルを含めると、コンポーネントを登録できないというエラーが表示されます。
[$injector:modulerr] Failed to instantiate module EmployeeInformation due to:
TypeError: Cannot read property 'controller' of undefined
at $CompileProvider.registerComponent [as component]
このコンポーネントへの参照を削除すると、ページは正常に読み込まれます。誰かが私が間違っていることを知っていますか?
編集:同じモジュール内に、同様に構成されたサービスがあります(関数にラップされ、空の配列なし-以下を参照)、正しく機能します:
(function () {
'use strict';
angular
.module('EmployeeInformation')
.service('EmployeeService', EmployeeService);
EmployeeService.$inject = ['$http'];
function EmployeeService($http) {
var apiPrefix = 'http://dvlemployees/api/employees';
this.find = find;
this.get = get;
this.getOne = getOne;
function find(queryObj) { }
function get() { }
function getOne(empNumber) { }
})();
EDIT2:@Frondorのおかげで、本当の問題はangular.component
、オブジェクトを定義する前にオブジェクトを呼び出していたことにあることがわかりました。セクションを一番上に移動するvar EmployeeDetail
と、問題が修正されました。