2017-02-18 9 views
0

私は現在フォームを提出しています。私は私のNGの提出が動作しないと仮定します。私はクロームで何も動作しないようにしようとしていますが、Firefoxでは動作します。 混乱してきそうです。ここに私のコードです:角度js ng-submitが動作しない

//コントローラ

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> 
+0

ブラウザの開発者コンソールを見ましたか? – statosdotcom

答えて

0
try this.. 

<button type="submit" class="btn btn-primary">Suggest</button> 
//change this line- 
<input type="submit" class="btn btn-primary" name="" id="" value="Suggest" /> 

hope it works. 
+0

ねえ、それは動作します!ありがとう、しかし、代わりにボタンを使用して入力を使用する理由は? – GMassimiliano

0
<html lang="en"> 

<head> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script> 
<script> 
    angular.module('SuggestionBox', []).controller("HomeController", ["$scope", function($scope) { 
     $scope.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 = ""; 
     }; 
    }]); 
</script> 
</head> 

<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> 
</body> 

</html> 

このコードは、あなたの要件ごとに取り組んでいます。提案

app.controller("HomeController",["$scope","suggestions",function($scope,suggestions){ 

依存あなたのための問題を作成していた提案。

+0

とにかく "提案"は私のサービスですので、私はそれを入手して保存します – GMassimiliano

+0

この提案サービスの内部に書かれたコードを提供できますか? –

+0

それはすでに解決されています、私に助けてくれてありがとう – GMassimiliano