2016-07-15 15 views
0

私は一日中このことに固執しています。私は"メッセージを送信"を押すとanglejsでスコープ変数が変更されましたが、ビューは変更されません

<table> 
    <tr ng-repeat="x in usernames"> 
     <td>{{x.username}}</td> 
     <td> 
      <button type='button' ng-click='sendMessage()'>Send Message</button> 
     </td> 
     <td> 
      <button type="button" ng-click="deleteUser()">Delete User</button> 
     </td> 
    </tr> 
</table> 

、コントローラが正常に点火されます。

$scope.sendMessage = function() { 
    $scope.content_in = '<form novalidate>' 
     +'<label>Message: &nbsp</label> <input type="text" ng-model="message"/><br><br>' 
     +'<button id="mybutton" style="width:75px" ng-click="send()">Send</button>' 
     +'<input id="mycancel" style="width:75px" type="reset" value="Cancel"/>' 
     +'</form>'; 
} 

私は単純にcontent_in変数に格納されますメッセージフォームでの私のページを更新しようとしています。しかし、変更はビューに反映されません。

私も含ま:コントローラで

$scope.$watch('content_in', function() { 
    alert('hey, content_in has changed!'); 
}); 

を、と私は変更がコントローラで行われていることを確信しています。 ビューに変更を反映させるにはどうすればよいですか?

+1

をDIV追加するには、デザインのページで、次のアプローチ

myApp.controller("myController", function ($scope, $compile, myService) { $scope.sendMessage = function() { var content_in = '<form novalidate>' +'<label>Message: &nbsp</label> <input type="text" ng-model="message" /><br><br>' +'<button id="mybutton" style="width:75px" ng-click="send()">Send</button>' +'<input id="mycancel" style="width:75px" type="reset" value="Cancel" />' +'</form>'; var element = angular.element(document.querySelector("#myDiv")); element.empty(); element.append(content_in); $compile(element.contents())($scope); } }); 

を試してみてください。関連するマークアップを提供するか、jsFiddleまたはplunkerが最適です。どうも! –

+0

$ scopeを使用してみてください$ apply –

+1

代わりに 'ngShow'' ngIf'または' ngBindHtml'を使用できませんでしたか? –

答えて

1

が、これは

<div id="myDiv"> 
私はあなたのHTML内content_in` `のいずれかの使用を気づいていない

関連する問題