我目前堅持提交表單。我認爲我的ng-submit不起作用。我試圖在Chrome中運行沒有任何作品,而在Firefox中它運作。好像越來越糊塗 這裏是我的代碼:角js ng提交不工作
//控制器
app.controller("HomeController",["$scope","suggestions",function($scope,suggestions){
$scope.posts = suggestions.posts;
$scope.addSuggestion = function(){
//if input empty
if(!$scope.title || $scope.title === ""){
alert("wrong");
}
//push suggestions
$scope.posts.push({
title: $scope.title,
upvotes: 0
});
//after submit, clear input
$scope.title = "";
};
}]);
// HTML
<body ng-app="SuggestionBox" ng-controller="HomeController">
<h1 class="text-center">Suggestion Box</h1>
<section id="main">
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="well" ng-repeat="post in posts | orderBy:'-upvotes'">
<h3>{{post.title}}</h3>
<button type="button" class="btn btn-warning"><i class="fa fa-star"></i> {{ post.upvotes }}</button>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<form ng-submit="addSuggestion()">
<h3 class="text-center">Submit Your Suggestion</h3>
<div class="form-group">
<input type="text" class="form-control" placeholder="Great Ideas Here" ng-model="title"/>
</div>
<button type="submit" class="btn btn-primary">Suggest</button>
</form>
</div>
</div>
</div>
</section>
你見過瀏覽器開發者控制檯嗎? – statosdotcom