2017-09-25 59 views
-1

我想使用ng-bind僞指令在輸入文本字段中顯示值。有人可以幫我解決這個問題嗎?使用ng-bind指令

<div class="col-md-3"> 
    <input class="form-control" disabled="disabled" value="ng-bind="type""> 
</div> 

控制器:

$scope.type = $scope.name[0].type_of_request; 

我想在HTML page.I打印這種類型是不能夠實現that.Would有人幫

+0

「和」 –

+0

這不是什麼'ng-bind'是for;你爲什麼要用這個而不是'ng-model'? – Claies

+0

'ng-model'是一種雙向綁定。 'ng-bind'只是把這個值放入元素 –

回答

2

使用NG-模式代替

如果您需要單程綁定然後

<input class="form-control" disabled="disabled" ng-model="::type"> 

否則,如果您需要雙向結合

<input class="form-control" disabled="disabled" ng-model="type"> 
+0

::是一種方式綁定。這意味着它顯示輸入中的類型值。但改變輸入文字將不會改變 –

+0

類型的值@NevilleNazerane只是重新檢查我的答案已經更新 – jitender

+0

是的,我知道。我其實正在回答別人的評論。有人問爲什麼::? 現在那個人刪除了他的評論 –

1

var myApp = angular.module('myApp', []); 
 
myApp.controller('MyCtrl', function($scope, $timeout) { 
 
    $scope.type = "test"; 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script> 
 

 
<html ng-app="myApp"> 
 

 
<div ng-controller="MyCtrl"> 
 
    <input class="form-control" disabled="disabled" ng-model="type"> 
 
</div> 
 

 
</html>

NG-模式工作是在這裏很好,使用它:

<html ng-app="myApp"> 

<div ng-controller="MyCtrl"> 
<input class="form-control" disabled="disabled" ng-model="type"> 
</div> 
</html> 

或使用ng-value="type"

檢查下面的例子:

<div ng-app=""> 
 
    <p>Enter your Name: <input type="text" ng-model="name"></p> 
 
    <p>Hello <span ng-bind="name"></span>!</p> 
 
    <p>Hi <input type="text" value="{{name}}" /></p> 
 
    <p>Ahoy <input type="text" ng-value="name" /></p> 
 
</div> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
當您使用內報價,報價使用

+1

是'ng-value'也提供單向綁定。很好的答案和演示。 –