javascript
  • angularjs
  • angularjs-ng-click
  • 2016-09-27 79 views 1 likes 
    1

    Im试图更新点击地图按钮时的一些数据,但ng-click函数看起来不起作用。以下是我的代码。Angularjs ng-click不起作用

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

    当我点击地图按钮时,没有任何反应。没有错误也正在显示。任何帮助,这是非常感谢。由于提前

    +0

    'ng-click ='在哪里? “mapFields()”功能? – Sathish

    +1

    你的代码更隐晦和令人困惑 –

    +0

    你的传递$范围如何作为参数?到功能 –

    回答

    7

    根据您的视图ng-click="mapFields()"没有通过任何参数,

    HTML:

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

    所以,你的功能应该是

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

    DEMO

    +0

    谁downvoted?原因? – Sajeetharan

    +0

    我不低调。没有控制器如何访问? – Sathish

    +0

    @Sajeetharan,我试了上面的。但得到一个错误未捕获ReferenceError:$范围未定义 – vr3w3c9

    相关问题