2

I'm just new to angularjs i'm more on jquery and i just tried to used angular in post request same as how ajax works. but when i looked at my console.log() I saw a problem in which the output of my validation have a html tags

ouput

https://i.stack.imgur.com/G2Lbx.jpg

**CONTROLLER (codeigniter) **

public function auth(){
    $obj = json_decode(file_get_contents('php://input'));
    $_POST = json_decode(file_get_contents('php://input'),true);
    $this->form_validation->set_rules('name','Name','required|is_unique[users.name]');
    $this->form_validation->set_rules('password','Password','required');
    $this->form_validation->set_rules('cpassword','Confirm Password','required');
    
    if($this->form_validation->run()==FALSE){
        echo json_encode(validation_errors());
    }else{
        echo json_encode("no error");
    }
}

MY ANGULARJS

<script type="text/javascript">
var app = angular.module('app', []);
var base_url = window.location.origin+"/";

app.controller('myCtrl', function($scope,$http) {
$scope.message = "";
$scope.formData = {}
$scope.submit = function(){
    var regdata = {
        url: base_url+"main/auth",
        method: "POST",
        data: { 
            name: $scope.name,
            password: $scope.password,
            cpassword: $scope.cpassword 
        },
        headers: {'Content-Type': 'application/json'},
        

    }

    $http(regdata).then(function successCallback(response) {
            $scope.message = response.data;
            console.log($scope.message);

      }, function errorCallback(response) {
        alert('Something Went Wrong! :( ');
      });
}
});
</script>

MY VIEW

<h3>Sign Up Now</h3>
        <form method="post" id="form_signup" ng-submit="submit()">
            <p style="color:white">{{ message }}</p> 
            <!-- <p ng-model="message"></p> -->
            <input placeholder="Name" ng-model="formData.name" type="text" />
            <span class="icons i3"><i class="fa fa-user" aria-hidden="true"></i></span>
            <!-- <input placeholder="E-MAIL" name="email" type="email"  />
            <span class="icons i4"><i class="fa fa-envelope-o" aria-hidden="true"></i></span>  -->
            <input placeholder="PASSWORD" ng-model="formData.password" type="password"  />
            <span class="icons i4"><i class="fa fa-key" aria-hidden="true"></i></span>
            <input placeholder="CONFIRM PASSWORD" ng-model="formData.cpassword"  type="password"  />
            <input type="submit"  value="Sign UP"  name="login">
        </form>
Community
  • 1
  • 1
rinru
  • 141
  • 4
  • 19
  • 1
    Seems to be the issue discussed in [AngularJS : Insert HTML into view](http://stackoverflow.com/q/9381926/1072229) – Grisha Levit Feb 13 '17 at 03:45

0 Answers0