vr3w3c9 vr3w3c9 - 11 months ago 78
AngularJS Question

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. 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'?>
<mapping targetIndex='0' sourceIndex='0' dataType='String' businessKey='1' alias='Practice'/>
<mapping targetIndex='1' sourceIndex='1' dataType='String' businessKey='0' alias='Client_Name'/>

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

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

Answer Source

According to your view ng-click="mapFields()" it does not pass any argument,


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

so,your function should be

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