我在 AngularJS 路由和控制器中遇到问题。这是代码:
索引.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: '/' });
});
联系人.js
var myApp = angular.module('contacts', []);
myApp.controller('ContactsCtrl', function ($scope) {
$scope.name = "omar";
});
但我收到此错误:
参数“ContactsCtrl”不是函数,未定义
有什么帮助吗?
像这样改变你的index.html;
<script src="index.js"></script>
<script src="contacts.js"></script>
并在 contact.js 中进行更改
var myApp = angular.module('contacts', []);
to
var myApp = angular.module('contacts');
带有两个参数的 Angular 模块,例如angular.module('contacts', []);
将创建一个新模块,但是带有单个参数的角度模块,例如angular.module('contacts');
将拾取现有模块。在这种情况下'contacts'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)