1

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'?>
<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

3
  • Where is ng-click="mapFields()" function? Commented Sep 27, 2016 at 10:17
  • 1
    you code is more obscure and confusing Commented Sep 27, 2016 at 10:17
  • how come your passing $scope as argument? to a function Commented Sep 27, 2016 at 10:17

1 Answer 1

4

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

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

Sign up to request clarification or add additional context in comments.

3 Comments

I am not downvoted. Without controller how is accesible?
@Sajeetharan, i tried the above.But getting an error Uncaught ReferenceError: $scope is not defined
@vr3w3c9 check the demo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.