ng-click not working when button is pushed Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of ng-click not working when button is pushed without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I am trying to get a function to execute when a button is clicked…

Here is my button:

<body ng-app="starter">

<div ng-controller="convertController">
    <button class="button button-block button-balanced" ng-click="convert()">
        Convert
    </button>
</div>

Here is my function:

var myApp = angular.module('starter',['ionic']);
myApp.controller('convertController', ['$scope', function($scope) {
    $scope.convert = function(){
       alert("convert");
    }                            
}]);

Why is the function not being called when I click the button?

Answer

That code is fine, it should work as you can see in the snippet below that is a copy paste of your code (except for the ionic dependency).

The problem probably comes from elsewhere. Please check your console for any error, Angular probably couldn’t initiate for another reason (for instance cannot resolve the ionic dependency?).

How to see errors using Chrome

How to see errors using Firefox

var myApp = angular.module('starter',[]);
myApp.controller('convertController', ['$scope', function($scope) {
    $scope.convert = function(){
       alert("convert");
    }                            
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="starter">

<div ng-controller="convertController">
    <button class="button button-block button-balanced" ng-click="convert()">
        Convert
    </button>
</div>
</body>
We are here to answer your question about ng-click not working when button is pushed - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji