fex-team / fis3-demo

fis3 demo
889 stars 347 forks source link

[fis3-angular-demo]Argument 'CualUserController' is not a function, got undefined #43

Open yinwer81 opened 8 years ago

yinwer81 commented 8 years ago

Error: [ng:areq] Argument 'CualUserController' is not a function, got undefined http://errors.angularjs.org/1.3.20/ng/areq?p0=CualUserController&p1=not%20aNaNunction%2C%20got%20undefined at http://127.0.0.1:8080/statics/bower_components/angular/angular.js:63:12 at assertArg (http://127.0.0.1:8080/statics/bower_components/angular/angular.js:1590:11) at assertArgFn (http://127.0.0.1:8080/statics/bower_components/angular/angular.js:1600:3) at http://127.0.0.1:8080/statics/bower_components/angular/angular.js:8493:9 at http://127.0.0.1:8080/statics/bower_components/angular/angular.js:7661:34 at forEach (http://127.0.0.1:8080/statics/bower_components/angular/angular.js:334:20) at nodeLinkFn (http://127.0.0.1:8080/statics/bower_components/angular/angular.js:7648:11) at compositeLinkFn (http://127.0.0.1:8080/statics/bower_components/angular/angular.js:7140:13) at publicLinkFn (http://127.0.0.1:8080/statics/bower_components/angular/angular.js:7019:30) at http://127.0.0.1:8080/statics/bower_components/ui-router/release/angular-ui-router.js:4089:9(anonymous function) @ angular.js:11706 angular.js:1590 Uncaught Error: [ng:areq] Argument 'fn' is not a function, got Object http://errors.angularjs.org/1.3.20/ng/areq?p0=fn&p1=not%20a%20function%2C%20got%20Object

我在fis3-angular-demo的modules/pages下,新增一个cualusers模块。

cualuser.js

module.exports = { url: '/cualusers', template: __inline('./cualusers.html'), //注意如果开启压缩,应采取此方式注入对象,否则压缩后将找不到 controller : ["$scope","$injector",function($scope, $injector) { //支持异步加载controller require.async('/modules/pages/cualusers/cualusers.async.js', function(ctrl) { $injector.invoke(ctrl, this, {'$scope': $scope}); }); }] };

cualuser.html

<div class="row" ng-controller="CualUserController"> ... </div>

cualusers.async.js

`angular.module('xxx').controller('CualUserController', function($scope, $http) { $scope.users = [];

$http.get('exingcai/cualuser').success(function (data, status, headers, config) {
    $scope.users = data;
}).error(function (data, status, headers, config) {
    $scope.errorMessage = "Can't retrieve cualuser list!";
});`

});

zhangtao07 commented 8 years ago

尽量别用异步加载,在 angular里面显得有点另类。。