2016-07-12 11 views
0

次のようにします。AngularJSアップデート入力と2つのモデルonSubmit

ディレクティブ1 - >ユーザーフォームに表示 ディレクティブ2 - >ユーザーが[送信]ボタンを押したときにのみ更新されます。

Examplesnippet:

<h2>{{directive1}}</h2> <!-- This is seen by the user when he changes directive 1 !--> 
<input type="text" class="form-control" ng-model="directive1" name="input" placeholder="This is the primary input (this needs to be updated when the form is used by the user. "> 
<h3>{{directive2}}</h3> <!-- This should only be changed when the user presses the submit button on the form ng-model-options: {onUpdate: 'submit'} 

答えて

0

ここで変更した例。 directive1ユーザ入力に関する更新。 directive2の更新情報を入力してください。 JSFiddle

var app = angular.module("myApp", []); 
 
app.controller("myCtrl", function($scope) { 
 
    $scope.directive1 = "stackoverflow"; 
 
    $scope.directive2 = "submit your text"; 
 
    $scope.myFunc = function() { 
 
     $scope.directive2 = $scope.directive1; 
 
    } 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="myApp" ng-controller="myCtrl"> 
 
<h2>{{directive1}}</h2> 
 
<form ng-submit="myFunc()"> 
 
<input type="text" class="form-control" ng-model="directive1" name="input" placeholder=""> 
 
</form> 
 
<h3>{{directive2}}</h3> 
 
</div>

関連する問題