gpt4 book ai didi

javascript - 错误 : Argument 'ContactController' is not a function, 未定义

转载 作者:行者123 更新时间:2023-11-30 12:28:38 24 4
gpt4 key购买 nike

我正在尝试使用 angularjs 在我的简单网络应用程序中创建一个小 Controller ,但出现此错误:

Error: Argument 'ContactController' is not a function, got undefined

这是我到目前为止所做的:

Angular (ContactsController.js):

var mainApp = angular.module('mainApp', []);

mainApp.ContactController = ("ContactController", ["$scope", function($scope) {
$scope.contatti = {};
$scope.contatti.contacts = ["test.one@gmail.com", "test.two@gmail.com"];

$scope.contatti.addContacts = function () {
$scope.contatti.contacts.push($scope.newcontact);
$scope.contatti.newcontact = "";
};

}]);

html:

    <!DOCTYPE html>
<html data-ng-app="mainApp" data-ng-controller="ContactController">

<head>
<meta charset="utf-8">
<script src="jquery-1.11.2.js"></script>
<script src="angular-1.3.12/angular.js"></script>
<script type="text/javascript" src="angular-1.3.12/angular.js"></script>
<script type="text/javascript" src="angular-1.3.12/angular-cookies.js"></script>
<script type="text/javascript" src="angular-1.3.12/angular-resource.js"></script>
<script type="text/javascript" src="angular-1.3.12/angular-sanitize.js"></script>

<link type="text/css" rel="stylesheet" href="ukit-2.16.2/css/uikit.almost-flat.css" />
<script src="ContactsController.js"></script>
<link type="text/css" rel="stylesheet" href="main.css" />
</head>

<body>

<div>
Email:<input type="text" ng-model="contatti.newcontact" />

<button ng-click="addContacts()">Add</button>

<h2>Contacts</h2>
<ul>
<li ng-repeat="contact in contatti.contacts"> {{ contact }} </li>
</ul>

</div>
</body>
</html>

最佳答案

应该是这样的:-

mainApp.controller("ContactController", ["$scope", function($scope) {
$scope.contatti = {};
$scope.contatti.contacts = ["test.one@gmail.com", "test.two@gmail.com"];

$scope.contatti.addContacts = function () {
$scope.contatti.contacts.push($scope.newcontact);
$scope.contatti.newcontact = "";
};

}]);

关于javascript - 错误 : Argument 'ContactController' is not a function, 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28478339/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com