somesh tripathi
somesh tripathi

Reputation: 79

IONIC Click Event. Not Working

The Code Below Works Perfectly fine when i run it in browser. But when the same code is placed in ionic specific code. it doesn't Can you guys help me through it. Thanks in Advace.

<div ng-app="myapp" ng-controller="empcontroller">
<form>
        <input type="text" ng-model="empno">
       <input type="text" ng-model="empname"> 
        <input type="button" value="submit" ng-click="insertdata()" /> 
</form>
<script>
    var app = angular.module('myapp',[]);
    app.controller('empcontroller',function($scope,$http){
        $scope.insertdata=function(){
            $http.post("localhost/Angular/insert.php",{
                'empno' : $scope.empno, 'empname' : $scope.empname
            }).sucess(function(data,status,headers,config)
            {
                console.log("Data inserted Sucessfully");
            });
        }
    });
</script>

The Pic Will Give a Little Bit more Explanation The Click Event Doesn't Occur

Whereas This Does

Upvotes: 0

Views: 3381

Answers (2)

gsthina
gsthina

Reputation: 1100

Your HTML Code can be as follows.

<div ng-app="myapp" ng-controller="empcontroller">
    <ion-input type="text" ng-model="empno"></ion-input>
    <ion-input type="text" ng-model="empname"></ion-input>
    <button ion-button type="submit" block ng-click="insertdata()">Submit</button></ion-input>
</div>

The above is in AngularJS. If you want to use Angular2, then follow the below code.

<div ng-app="myapp" ng-controller="empcontroller">
  <form (ngSubmit)="logForm()">
    <ion-input type="text" [(ngModel)]="empno"></ion-input>
    <ion-input type="text" [(ngModel)]="empname"></ion-input>
    <button ion-button type="submit" block (click)="insertdata()">Submit</button>
  </form>
</div>

Moreover, I would suggest you to write your codes in the respective files. That is, your HTML code into the .html and SCRIPT code into the .ts or .js file.

Also, working on browser is different than working on an Android Build.

Upvotes: 1

Prajwal Bati
Prajwal Bati

Reputation: 195

You need to use recommended DI style otherwise problems will happen in minificaiton of js, and angularjs won't find dependencies.

app.controller('empcontroller', ['$scope', '$http' ,function($scope,$http){

}]);

Upvotes: 0

Related Questions