0

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

3
  • Why don't you use Ionic tags there? Commented Mar 9, 2017 at 7:02
  • I tired @GSURENDARTHINA But the Result was same. if you could guide me with the same it would be really helpful. Commented Mar 9, 2017 at 7:19
  • spell check on success function, there's a typo. Commented Mar 10, 2017 at 10:27

2 Answers 2

1

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.

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

1 Comment

Thanks a ton Bro!!
0

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

}]);

1 Comment

This Code Works Perfectly When i run it from a browser. but it doesn't when i bundle the code with ionic

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.