【问题标题】:Angularjs: Error: [ng:areq] Argument '...' is not a function, got undefinedAngularjs:错误:[ng:areq] 参数 '...' 不是函数,未定义
【发布时间】:2016-11-12 11:02:13
【问题描述】:

使用 angular 1.5+ 启动我的应用程序

这是我的控制器代码

'use strict';

(function(){

class FlamingoController {
    constructor($http) {
        this.$http = $http;
        this.flamingo = [];
    }

    $onInit() {
        this.$http.get('/api/flamingo')
            .then(response => {
                this.flamingo = response.data;
            })
    }
}

angular.module('wildroseApp')
  .component('flamingo', {
    templateUrl: 'app/flamingo/flamingo.html',
    controller: FlamingoController,
  });

})();

当我试图在视图中添加我的控制器时

<div class="container" ng-controller="FlamingoController as ctrl">

我收到了

错误:[ng:areq] 参数 'FlamingoController' 不是函数,未定义

【问题讨论】:

  • 你不需要在你的 div 标签中定义 ng-controller。您已经在 angular.module 代码中定义了控制器。
  • 感谢已修复

标签: javascript angularjs


【解决方案1】:

您可能忘记了 ng-app 或将文件添加到头部。已检查网络,控制器已加载?

我从来没有使用过 angular,所以我会删除它。

【讨论】:

    猜你喜欢
    • 2015-09-02
    • 2015-10-20
    • 2014-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-18
    • 2015-11-03
    • 2016-10-23
    相关资源
    最近更新 更多