2017-06-21 78 views
0

我有如下的HTML如何从角度js中的其他标签属性获取模型?

<input class="form-check-input" data-fieldId="79" ng-model="test1" type="text" name="test1"> 


<input class="form-check-input" data-fieldId="80" ng-model="test2" type="text" name="test2"> 

我有数据fieldId在控制器。我需要通过字段id和其角度值来查找输入元素。

回答

-1

我不完全理解你的问题,但你可以试试这个。

<!DOCTYPE html> 
     <html lang="en"> 
     <head> 

      <title>Ristorante Con Fusion: Menu</title> 
       <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> 
       <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-route.js"></script> 

       <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-grid/4.0.6/ui-grid.min.js"></script> 
       <style> 
       .grid { 
     width: 500px; 
     height: 250px; 
    } 
       </style> 
     </head> 
     <body> 


     <div ng-app="myApp" ng-controller="userController"> 
     <input class="form-check-input" data-fieldId="79" ng-model="test1" ng-change="textchanged()" type="text" name="test1"> 


     <input class="form-check-input" data-fieldId="80" ng-model="test2" ng-change="textchanged()" type="text" name="test2"> {{result1}} {{result2}} 
     </div> 

      <script> 
     var app = angular.module('myApp', ["ngRoute"]); 

     app.controller('userController', function ($scope) { 

     $scope.textchanged = function(){ 
      $scope.result1 = $scope.test1; 
      $scope.result2 = $scope.test2 
     } 

     }); 
      </script> 
     </body> 
     </html> 
+0

为什么使用ng-change不需要这个?我只需要找出来自data-fieldId的输入元素 – bittu

+0

输入元素意味着您在文本框中给出的数据是正确的? – Arun

+0

是需要查找模型是动态的元素及其值。 – bittu