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

时间:2017-06-21 09:47:22

标签: javascript html angularjs

我有以下html

 <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">

我在控制器中有data-fieldId。我需要通过字段id找到输入元素,并以角度方式找到它的值。

1 个答案:

答案 0 :(得分:-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>