gpt4 book ai didi

javascript - 一个简单的平均应用程序不工作

转载 作者:行者123 更新时间:2023-11-30 11:46:46 27 4
gpt4 key购买 nike

我正在尝试运行一个简单的平均应用程序,但它不工作。我收到以下错误:http://errors.angularjs.org/1.4.9/ng/areq?p0=meetupsController&p1=not%20a%20function%2C%20got%20undefined (参数“meetupsController”不是函数,未定义)

这是我的代码

服务器.js

var express = require('express'),
app = express();

app.get('/', function(req, res){
res.sendfile(__dirname + '/client/views/index.html');

});


app.use('/js', express.static(__dirname + '/client/js'));
app.listen(3000, function() {
console.log('I mlistening on 3000');
})

我的 Angular Controller :

var app = angular.module('meetupApp', ['ngResource']);
app.controller('meetupsController', ['$scope', '$resource', function($scope, $resource){

$scope.meetups = [
{name : "First"},
{name : "second"},
]

$scope.createMeetup = function(){
$scope.meetups.push({name: $scope.meetupName});
$scope.meetupName='';
}

}])

mu html 文件:

<html ng-app>
<head>
<title></title>
</head>
<body>

<div ng-controller="meetupsController">
<h1>There are {{meetups.length}} meetups</h1>
<ul>
<li ng-repeat="meetup in meetups">
{{meetup.name}}
</ul>
<form ng-submit="createMeetup()">
<input type="text" placeholder="Meetup name" ng-model="meetupName"></input>
<button type="submit">Add</button>
</form>
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.9/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.9/angular-resource.min.js"></script>
<script type="text/javascript" src="/js/controllers/meetups-controller.js"></script>
</body>
</html>

请帮忙

最佳答案

在你的<html ng-app>你应该像这样添加你的 Angular 应用程序:

<html ng-app="meetupApp">
...
</html>

关于javascript - 一个简单的平均应用程序不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40722872/

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