2016-09-16 4 views
0

をされて使用してngのモデルからデータを取得することはできません。は、ここに私の.htmlをsignalr

<ul class="messages list-unstyled" ng-repeat="newMessage in messages"> 
        <li> 
         <p> 
          <span class="username">{{newMessage.username}}</span><br /> 
         </p> 
         <p> 
          <span> {{newMessage.message}}</span> 
         </p> 

         <p class="no-pad-bottom date-posted">Send {{ newMessage.date }} <span /></p> 

         <div class="comments"> 
          <ul class="list-unstyled" ng-repeat="newComment in comments"> 
           <li> 
            <p> 
             <span class="commentor"> {{newComment.username}}</span> 
             <span> {{newComment.message}}</span> 
            </p> 
            <p class="no-pad-bottom date-posted">Send {{ newComment.date }} <span /></p> 
           </li> 

          </ul> 

          <form class="add-comment"> 
           <div class="row"> 
            <div class="col-md-10"> 
             <input type="text" class="form-control" ng-model="myComment" placeholder="Add a comment" /> 
            </div> 
            <div class="col-md-2"> 
             <button class="btn btn-default btn-sm" type="submit" ng-click="addComment(newMessage.id)">Comment</button> 
            </div> 
           </div> 
          </form> 
         </div> 
        </li> 
       </ul> 

すべてが動作しています。 jsのコントローラのメソッド

$scope.addComment = function (messageId) { 
     myChatHub.server.addComment(messageId, userName, $scope.myComment); 
    }; 

であるあなたは間違っているものを私に教えてくださいすることができ、ここで

私は私のメッセージを送信することができ、そして私も記事を送ることができますが、私はNG-モデル=「myComment」

からnullを取得します?あなたがオブジェクト

ng-repeatを使用して..常にng-modelにドットを持つのか、つまり黄金のルールを破っている

答えて

0

は子スコープを作成し、あなたのプリミティブは、そのためだけのプリミティブ以来、子スコープ内に存在ng-modelに割り当て継承がない。

コントローラ

$scope.model={} 

にモデルオブジェクトを作成し、ng-model="model.myComment"ことを使用してにあなたのポストを変更します。

$scope.addComment = function (messageId) { 
     myChatHub.server.addComment(messageId, userName, $scope.model.myComment); 
}; 

This 3 minute video

+0

はあなたに多くのことを感謝非常に啓発されます! – mrnvdvmv

関連する問題