簡體   English   中英

為什么我的第二個ng模型不返回插入的值?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM