我知道,这个话题有,但是我有类似的问题。 我的本地主机有一些数据。
未捕获的错误:[$ injector:modulerr]由于以下原因,无法实例化模块myApp: 错误:[ng:areq]参数'fn'不是函数,有字符串
我的错误在哪里?请帮我。 :(
app.js
'use strict';
(function () {
let myApp = angular.module('myApp', ['ngRoute']);
myApp.controller('userController', ['$http', function ($http) {
let vm = this;
$http.get("http://localhost:8080/Market/users").then(function (response) {
vm.usersForm = response.data;
})
}]);
myApp.config('$stateProvider', [ function($stateProvider) {
$stateProvider.state('index', {
url: "http://localhost:63342/demo2/app/",
templateUrl: "index.html",
controller: "userController"
})
}]);
}());
index.html
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>My AngularJS App</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular-route.js"></script>
<script src="app.js" type="text/javascript"></script>
</head>
<body>
<div ng-app="myApp" ng-controller="userController as vm">
<label>{{vm.usersForm.firstName}}</label>
</div>
</body>
</html>
当我调试index.html时,控制台屏幕:
Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [ng:areq] Argument 'fn' is not a function, got string
http://errors.angularjs.org/1.2.32/ng/areq?p0=fn&p1=not%20a%20function%2C%20got%20string
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:78:12
at assertArg (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:1511:11)
at assertArgFn (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:1521:3)
at annotate (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:3291:5)
at Object.invoke (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:3945:21)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:3886:37
at forEach (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:325:18)
at loadModules (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:3873:5)
at createInjector (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:3813:11)
at doBootstrap (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:1446:20)
http://errors.angularjs.org/1.2.32/$injector/modulerr?p0=myApp&p1=Error%3A%20%5Bng%3Aareq%5D%20Argument%20'fn'%20is%20not%20a%20function%2C%20got%20string%0Ahttp%3A%2F%2Ferrors.angularjs.org%2F1.2.32%2Fng%2Fareq%3Fp0%3Dfn%26p1%3Dnot%2520a%2520function%252C%2520got%2520string%0A%20%20%20%20at%20https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.32%2Fangular.js%3A78%3A12%0A%20%20%20%20at%20assertArg%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.32%2Fangular.js%3A1511%3A11)%0A%20%20%20%20at%20assertArgFn%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.32%2Fangular.js%3A1521%3A3)%0A%20%20%20%20at%20annotate%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.32%2Fangular.js%3A3291%3A5)%0A%20%20%20%20at%20Object.invoke%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.32%2Fangular.js%3A3945%3A21)%0A%20%20%20%20at%20https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.32%2Fangular.js%3A3886%3A37%0A%20%20%20%20at%20forEach%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.32%2Fangular.js%3A325%3A18)%0A%20%20%20%20at%20loadModules%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.32%2Fangular.js%3A3873%3A5)%0A%20%20%20%20at%20createInjector%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.32%2Fangular.js%3A3813%3A11)%0A%20%20%20%20at%20doBootstrap%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.32%2Fangular.js%3A1446%3A20)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:78:12
at assertArg (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:1511:11)
at assertArgFn (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:1521:3)
at annotate (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:3291:5)
at Object.invoke (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:3945:21)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:3886:37
at forEach (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:325:18)
at loadModules (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:3873:5)
at createInjector (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:3813:11)
at doBootstrap (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:1446:20)
http://errors.angularjs.org/1.2.32/$injector/modulerr?p0=myApp&p1=Error%3A%20%5Bng%3Aareq%5D%20Argument%20'fn'%20is%20not%20a%20function%2C%20got%20string%0Ahttp%3A%2F%2Ferrors.angularjs.org%2F1.2.32%2Fng%2Fareq%3Fp0%3Dfn%26p1%3Dnot%2520a%2520function%252C%2520got%2520string%0A%20%20%20%20at%20https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.32%2Fangular.js%3A78%3A12%0A%20%20%20%20at%20assertArg%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.32%2Fangular.js%3A1511%3A11)%0A%20%20%20%20at%20assertArgFn%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.32%2Fangular.js%3A1521%3A3)%0A%20%20%20%20at%20annotate%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.32%2Fangular.js%3A3291%3A5)%0A%20%20%20%20at%20Object.invoke%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.32%2Fangular.js%3A3945%3A21)%0A%20%20%20%20at%20https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.32%2Fangular.js%3A3886%3A37%0A%20%20%20%20at%20forEach%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.32%2Fangular.js%3A325%3A18)%0A%20%20%20%20at%20loadModules%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.32%2Fangular.js%3A3873%3A5)%0A%20%20%20%20at%20createInjector%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.32%2Fangular.js%3A3813%3A11)%0A%20%20%20%20at%20doBootstrap%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.32%2Fangular.js%3A1446%3A20)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:78:12
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:3907:15
at forEach (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:325:18)
at loadModules (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:3873:5)
at createInjector (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:3813:11)
at doBootstrap (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:1446:20)
at bootstrap (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:1461:12)
at angularInit (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:1370:5)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:22192:5
at HTMLDocument.trigger (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.js:2575:7)
答案 0 :(得分:-1)
已解决
我添加了这个库:
<script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
app.js已更新
'use strict';
(function () {
let myApp = angular.module('myApp', ['ui.router']);
myApp.controller('userController', ['$http', function ($http) {
let vm = this;
$http.get("http://localhost:8080/Market/users").then(function (response) {
vm.usersForm = response.data;
})
}]);
myApp.config('$stateProvider', [ function($stateProvider) {
$stateProvider.state('index', {
url: "http://localhost:63342/demo2/app/",
templateUrl: "index.html",
controller: "userController"
})
}]);
}());
index.html已更新
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>My AngularJS App</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/angular-loader/angular-loader.js"></script>
<script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script src="app.js" type="text/javascript"></script>
</head>
<body>
<div ng-app="myApp" ng-controller="userController as vm">
<label>{{vm.usersForm.firstName}}</label>
</div>
</body>
</html>