[英]In AngularyJs, why is my ng-model value not setting the selected option?
[英]Why my second ng-model does not return value as inserted?
我有这段代码和textarea1和textarea2。 我的问题是我无法操纵textarea2上的ng-model
。
如果我在textarea2中进行了任何更改...什么都没发生
有人可以帮我解决这个问题吗? 谢谢。
您可能会看到我到目前为止完成的代码。
var myApp = angular.module('myApp',[]); //myApp.directive('myDirective', function() {}); //myApp.factory('myService', function() {}); function MyCtrl($scope) { $scope.model1 = "Test1"; $scope.catch = function(model1) { $scope.model2 = model1; } }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script> <div ng-app="myApp"> <div ng-controller="MyCtrl"> Textarea 1 <textarea onkeypress="{{catch(model1)}}" ng-model="model1"></textarea> <br/> Text area 2 <textarea ng-model="model2"></textarea> <hr/> Textarea1: {{model1}} <br/> Textarea2: {{model2}} </div> </div>
您可以将onkeypress
更改为ng-change
吗?
var myApp = angular.module('myApp',[]); //myApp.directive('myDirective', function() {}); //myApp.factory('myService', function() {}); function MyCtrl($scope) { $scope.model1 = "Test1"; $scope.catch = function(model1) { $scope.model2 = model1; } }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script> <div ng-app="myApp"> <div ng-controller="MyCtrl"> Textarea 1 <textarea ng-change="catch(model1)" ng-model="model1"></textarea> <br/> Text area 2 <textarea ng-model="model2"></textarea> <hr/> Textarea1: {{model1}} <br/> Textarea2: {{model2}} </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.