Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 注册角度1.5组件时出错_Javascript_Angularjs_Angularjs Components - Fatal编程技术网

Javascript 注册角度1.5组件时出错

Javascript 注册角度1.5组件时出错,javascript,angularjs,angularjs-components,Javascript,Angularjs,Angularjs Components,我有以下1.5角组件: (function () { 'use strict'; angular .module('EmployeeInformation') .controller('EmployeeDetailCtrl', EmployeeDetailCtrl) .component('employeeDetail', EmployeeDetail); var EmployeeDetail = { templateUrl:

我有以下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() { }
  })();
[$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
部分移到顶部修复了该问题。

JavaScript HTML

view.html

<span>{{$ctrl.hello}} {{$ctrl.world}}</span>
{{$ctrl.hello}{{$ctrl.world}
您需要在模块名称后指定一个空数组,即使您没有在应用程序上使用任何依赖项

实例:

JavaScript HTML

view.html

<span>{{$ctrl.hello}} {{$ctrl.world}}</span>
{{$ctrl.hello}{{$ctrl.world}
您需要在模块名称后指定一个空数组,即使您没有在应用程序上使用任何依赖项

实例: 试试看:

(function (angular) {
  '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);
(函数(角度){
"严格使用",;
有棱角的
.module('EmployeeInformation',[])
.controller('EmployeeDetailCtrl',EmployeeDetailCtrl)
.component('employeeDetail',employeeDetail)
;
变量EmployeeDetail={
templateUrl:“../views/components/employeeDetail.html”,
控制器:“EmployeeDetailCtrl作为EMPDail”,
绑定:{
员工:“试试看:

(function (angular) {
  '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);
(函数(角度){
"严格使用",;
有棱角的
.module('EmployeeInformation',[])
.controller('EmployeeDetailCtrl',EmployeeDetailCtrl)
.component('employeeDetail',employeeDetail)
;
变量EmployeeDetail={
templateUrl:“../views/components/employeeDetail.html”,
控制器:“EmployeeDetailCtrl作为EMPDail”,
绑定:{

员工:“谢谢,但我在添加空数组时仍然会遇到相同的错误。@medievalgeek我已经用一个工作代码制作了一个plnkr示例,并更新了我的问题。请现在看一看您的更新为我指明了正确的方向。我必须先定义component对象,然后才能对其调用
angular.component
。我正在更新我的组件。”但我会接受你的回答,因为它帮助我找到了真正的问题。再次感谢!即使在有人“暗示”你之后,也能自己解决问题,这比让别人完成所有工作要好得多;)谢谢,但添加空数组后我仍然会遇到相同的错误。@medievalgeek我已经用一个有效代码制作了一个plnkr示例,并更新了我的问题。请现在看一看您的更新为我指明了正确的方向。在调用
angular.component
之前,我必须定义组件对象。我正在更新我的原始post但是会接受你的回答,因为它帮助我找到了真正的问题。再次感谢!能够自己解决问题,即使有人“暗示”你,这比让别人完成所有工作要好得多;)