Javascript 角度教程-我在哪里迷路了?
所以,我在学习Thinkster的Angular教程。我到了你将帖子折射成服务的地方,突然我的应用程序坏了。以下是我的代码(app.js): 以及HTML(index.HTML):Javascript 角度教程-我在哪里迷路了?,javascript,angularjs,Javascript,Angularjs,所以,我在学习Thinkster的Angular教程。我到了你将帖子折射成服务的地方,突然我的应用程序坏了。以下是我的代码(app.js): 以及HTML(index.HTML): 第一角应用程序 .glyphicon竖起大拇指{光标:指针} 假新闻 {{post.upvows} {{post.title} 添加新帖子 邮递 我已经尝试了很多不同的东西,在我的帖子周围移动,等等(上面列出的代码没有我的帖子,我把它们拿出来了) 我的臭虫在哪里 如果有帮助的话,下面是代码在我的浏览器中的外观:请
第一角应用程序
.glyphicon竖起大拇指{光标:指针}
假新闻
{{post.upvows}
{{post.title}
添加新帖子
邮递
我已经尝试了很多不同的东西,在我的帖子周围移动,等等(上面列出的代码没有我的帖子,我把它们拿出来了)
我的臭虫在哪里
如果有帮助的话,下面是代码在我的浏览器中的外观:请删除来自
帖子:[]代码>
var-app=angular.module('flapperNews',[]);
应用程序工厂('posts'[
函数(){
变量o={
员额:[]
};
返回o;
}
]);
app.controller('MainCtrl',['$scope','posts',
职能(范围、员额){
$scope.test='Hello world!';
$scope.posts=posts.posts;
$scope.addPost=函数(){
if(!$scope.title | |$scope.title==“”){
返回;
}
$scope.posts.push({
title:$scope.title,
得票数:0,
link:$scope.link
});
$scope.title='';
$scope.link='';
}
$scope.IncrementUpVoces=函数(其中){
其中,upvots+=1;
}
}
]);代码>
{{post.upvows}
{{post.title}
添加新帖子
邮递
console窗口中有错误吗?甚至还没有运行node或其他任何程序。只需在我的浏览器@Cerad.中导航到页面,$scope.posts=posts.posts;在浏览器控制台窗口中尝试$scope.posts=posts()。按F12。你可能会感到惊讶。我在app.js(posts:[])的第5行得到了一个“属性列表后缺少}”的消息
var app = angular.module('flapperNews', []);
app.factory('posts', [function(){
var o = {
posts: [];
};
return o;
}]);
app.controller('MainCtrl', [
'$scope', 'posts',
function($scope,posts){
$scope.test = 'Hello world!';
$scope.posts = posts.posts;
$scope.addPost = function(){
if(!$scope.title || $scope.title === '') { return; }
$scope.posts.push({
title: $scope.title,
upvotes: 0,
link: $scope.link
});
$scope.title = '';
$scope.link = '';
}
$scope.incrementUpvotes = function(which){
which.upvotes += 1;
}
}]);
<html>
<head>
<title> First Angular App </title>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.10/angular.min.js"></script>
<script src="app.js"></script> <!-- Angular app -->
<style> .glyphicon-thumbs-up { cursor:pointer } </style>
</head>
<body ng-app="flapperNews" ng-controller="MainCtrl">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="page-header">
<h1>Flapper News</h1>
</div>
<div ng-repeat="post in posts | orderBy:'-upvotes'">
<span class="glyphicon glyphicon-thumbs-up"
ng-click="incrementUpvotes(post)"></span>
{{post.upvotes}}
<span style="font-size:20px; margin-left:10px;">
<a ng-show="post.link" href="{{post.link}}">
{{post.title}}
</a>
<span ng-hide="post.link">
{{post.title}}
</span>
</span>
</div>
<form ng-submit="addPost()"
style="margin-top:30px;">
<h3>Add a new post</h3>
<div class="form-group">
<input type="text"
class="form-control"
placeholder="Title"
ng-model="title"></input>
</div>
<div class="form-group">
<input type="text"
class="form-control"
placeholder="Link"
ng-model="link"></input>
</div>
<button type="submit" class="btn btn-primary">Post</button>
</form>
</div>
</div>
</body>
</html>