参数“ContactsCtrl”不是一个函数,得到了不确定 [英] Argument 'ContactsCtrl' is not a function, got undefined
本文介绍了参数“ContactsCtrl”不是一个函数,得到了不确定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有在AngularJS路由和控制器的一个问题。这里是code:
I'm having a problem in AngularJS routing and controllers. Here is the code:
的index.html
<!DOCTYPE html>
<html ng-app="contacts">
<head>
<script src="libs/angular.min%20(1).js"></script>
<script src="contacts.js"></script>
<script src="index.js"></script>
<title></title>
</head>
<body >
<div data-ng-view=""></div>
</body>
</html>
index.js
var myApp = angular.module('contacts', []);
myApp.config(function ($routeProvider) {
$routeProvider
.when('/', { controller: 'ContactsCtrl', templateUrl: '/views/show-contacts.html' })
//.when('/view2', { controller: 'MyCont', templateUrl: 'V2.htm' })
.otherwise({ redirectTo: '/' });
});
contacts.js
var myApp = angular.module('contacts', []);
myApp.controller('ContactsCtrl', function ($scope) {
$scope.name = "omar";
});
但我发现了这个错误:
but I'm getting this error:
参数ContactsCtrl不是一个函数,得到了不确定
Argument 'ContactsCtrl' is not a function, got undefined
任何帮助吗?
推荐答案
您重新定义您的应用程序在 index.js
,所以在 contacts.js
丢失。取下此行index.js
:
You are redefining your app in index.js
, so the controller created in contacts.js
is lost. Remove this line from index.js
:
var myApp = angular.module('contacts', []);
这篇关于参数“ContactsCtrl”不是一个函数,得到了不确定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文