简体   繁体   English

AngularJS ng-click不起作用

[英]Angularjs ng-click not working

Im trying to update some data when the map button is clicked, but the ng-click function doesnt seem to work. 我试图在单击地图按钮时更新一些数据,但是ng-click函数似乎不起作用。 Below is my code. 下面是我的代码。

<textarea id="xmltest" class="form-control"  style="margin-top:2%; width: 60%;" rows="10" >
Resulting definition:<![CDATA[<?xml version='1.0' encoding='UTF-8'?>
<ColumnMapping>
    {{result}}
    <mapping targetIndex='0' sourceIndex='0' dataType='String' businessKey='1' alias='Practice'/>
    <mapping targetIndex='1' sourceIndex='1' dataType='String' businessKey='0' alias='Client_Name'/>
</ColumnMapping>
]]> 
</textarea>

<a style="margin-top: 10%;margin-right: -70%" href="#" class="btn btn-primary"  ng-click="mapFields()"  id="MappingFields">Map</a>

<script type="text/javascript">
    mapFields = function($scope){
    $scope.result= "Code works";
    };
</script>
</body>

When I click on the map button, nothing happens. 当我单击地图按钮时,什么也没有发生。 No error is also getting displayed. 也不会显示任何错误。 Any help on this is much appreciated. 任何帮助对此表示感谢。 Thanks in Advance 提前致谢

According to your view ng-click="mapFields()" it does not pass any argument, 根据您的观点ng-click="mapFields()"它不会传递任何参数,

HTML: HTML:

 <body ng-controller="dobController">
     <button ng-click="mapFields()">show result </button>
     {{result}}
  </body>

so,your function should be 所以,你的功能应该是

var app = angular.module('todoApp', [])
app.controller("dobController", ["$scope",
  function($scope) {
    $scope.mapFields = function() {
      $scope.result = "Code works";
    };

  }
]);

DEMO 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM