2015-11-30 194 views
0

我有一個單選按鈕的值被選擇這樣的:如何一個角模型綁定到另一個NG-模型

<input type="radio" ng-model="lesson.sectionID" value="{{section.$id}}"> 

我想的是輸入到另一個模型的值綁定,我試圖以下:

<input type="text" ng-model="module.sectionID" ng-bind="lesson.sectionID"> 

<input type="text" ng-model="module.sectionID" ng-value="lesson.sectionID"> 

當我試圖NG-值它的文字輸入設置爲正確的值,但ACTUA沒有設置模型的值。

回答

0

你可能尋找這種解決方案

angular.module('choices', []) 
    .controller("MainCtrl", ['$scope', function($scope) { 

    $scope.color = ''; 

    $scope.colors = [ 
     "Red", 
     "Green", 
     "Blue", 
     "" 
    ]; 

    $scope.changeColor = function(){ 
     $scope.color = "Red" 
    }; 

}]); 



<html> 
<head> 
<body ng-app="choices" ng-controller="MainCtrl"> 
    <div ng-repeat="color in colors"> 
    <input type="radio" ng-model="$parent.color" ng-value="color" id="{{color}}" name="color"> 
     <label > 
     {{color || 'Other'}} 
     </label> 
     <input type="text" ng-model="$parent.color" ng-show="color==''"> 
    </div> 
    <p></p> 
    The chosen color is <strong>{{color}}</strong> 
    <p></p> 
    <button ng-click="changeColor()">Change color</button> 
</body> 
</html> 
相關問題