我是角度js的新手,正在创建一个简单的应用程序。但是,当我尝试运行它时,绑定不起作用。我也得到一个控制台错误,说错误:[ng:areq]参数'meetupsController'不是函数,未定义。这是我的代码:
var app = angular.module('meetupApp', ['ngResource']);
这是我的meetups-controller.js:
app.controller('meetupsController', ['$scope', '$resource', function($scope, $resource){
var Meetup = $resource('/api/meetups');
$scope.meetups = [
{ name: "MEAN SF Developers" },
{name: "Some other meetups" }
]
$scope.createMeetup = function(){
var meetup = new Meetup();
meetup.name = $scope.meetupName;
meetup.$save();
}
}]);
这是我的index.html:
<!DOCTYPE html>
<html ng-app="meetupApp">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<!-Meetups View->
<div ng-controller="meetupsController">
<h1>There are {{meetups.length}} meetups</h1>
<ul>
<li ng-repeat="meetup in meetups">
{{meetup.name}}
</li>
</ul>
<form ng-submit="createMeetup()">
<input type="text" placeholder="Meetup name" ng-model="meetupName"></input>
<button type="submit">Add</button>
</form>
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-resource.js"></script>
<script type="text/javascript" src="/js/app.js"></script>
<script type="text/javascript" src"/js/controllers/meetups-controller"></script>
</body>
非常感谢您的帮助!
答案 0 :(得分:1)
您的控制器未正确加载,因为您在脚本中缺少.js
。
转换此
<script type="text/javascript" src"/js/controllers/meetups-controller"></script>
到这个
<script type="text/javascript" src"/js/controllers/meetups-controller.js"></script>