angularjs update button text based $http responses ng-click











up vote
0
down vote

favorite












I'm trying to update button value on-click based $http responses. I want to change button value to Processing... while making $http request with ng-click function. And based on Success/Error response, need to update text Success and Try Again etc.



I'm using ui-router and I've different form elements distributed in different states, e.g. Email, User, Password etc.



In my View, I've following code in Email State.



<div ng-controller="RegisterEmailController">
<div class="form-group" style="position: relative;" ng-class="{ 'has-error': form.useremail.$dirty && form.useremail.$error.required && form.useremail.$invalid }">
<input type="email" name="useremail" id="useremail" ng-model="RegisterEmailController.userDetail.useremail" ng-required="true">
<span ng-show="form.useremail.$dirty && form.useremail.$error.required" class="help-block text-sm text-danger pl-4">Oops! Incorrect email address, or field is empty</span>
<span ng-hide="form.useremail.$dirty && form.useremail.$error.required" class="help-block d-block text-sm text-danger px-4">{{ErrorMsg}}</span>
</div>
<button type="button" ng-click="RegisterEmailController.nexStep()">{{buttonTxt}}</button>
</div>


In my Controller



var controller = this;
$scope.buttonTxt = 'Next Step';

controller.nexStep = function() {
$scope.buttonTxt = 'Processing...';
if ( validation_conditions ) {
$http({
method: "POST",
url: ApiURL,
headers: { "Content-Type": "application/json" },
data: getData
}).then(function success(response) {
$scope.buttonTxt = 'Success';
}, function error(response) {
$scope.buttonTxt = 'Try Again';
return;
});
} else {
$scope.buttonTxt = 'Try Again';
return;
}
}


With above code i can't be able to change button text on click, i tried with controller.buttonTxt as well but it doesn't print value at all on init. I also tried ng-bind directive but no luck.



Please assist me where I'm doing wrong. As far as i can estimate that $scope might conflicting with this (var controller = this;) in controller.



Also how can i add success/error class to input parent element based on response?



Thanks for reading my query and i appreciate your help in advance.










share|improve this question


















  • 1




    You need to assign a controller alias in ng-controller when not using $scope
    – charlietfl
    Nov 19 at 23:30












  • Can u make a plunkr with the code?
    – ppollono
    Nov 19 at 23:55










  • Thanks @charlietfl, by assinging controller alias my problem is resolved, though have to fix couple of more things.
    – Umair Razzaq
    Nov 20 at 5:37















up vote
0
down vote

favorite












I'm trying to update button value on-click based $http responses. I want to change button value to Processing... while making $http request with ng-click function. And based on Success/Error response, need to update text Success and Try Again etc.



I'm using ui-router and I've different form elements distributed in different states, e.g. Email, User, Password etc.



In my View, I've following code in Email State.



<div ng-controller="RegisterEmailController">
<div class="form-group" style="position: relative;" ng-class="{ 'has-error': form.useremail.$dirty && form.useremail.$error.required && form.useremail.$invalid }">
<input type="email" name="useremail" id="useremail" ng-model="RegisterEmailController.userDetail.useremail" ng-required="true">
<span ng-show="form.useremail.$dirty && form.useremail.$error.required" class="help-block text-sm text-danger pl-4">Oops! Incorrect email address, or field is empty</span>
<span ng-hide="form.useremail.$dirty && form.useremail.$error.required" class="help-block d-block text-sm text-danger px-4">{{ErrorMsg}}</span>
</div>
<button type="button" ng-click="RegisterEmailController.nexStep()">{{buttonTxt}}</button>
</div>


In my Controller



var controller = this;
$scope.buttonTxt = 'Next Step';

controller.nexStep = function() {
$scope.buttonTxt = 'Processing...';
if ( validation_conditions ) {
$http({
method: "POST",
url: ApiURL,
headers: { "Content-Type": "application/json" },
data: getData
}).then(function success(response) {
$scope.buttonTxt = 'Success';
}, function error(response) {
$scope.buttonTxt = 'Try Again';
return;
});
} else {
$scope.buttonTxt = 'Try Again';
return;
}
}


With above code i can't be able to change button text on click, i tried with controller.buttonTxt as well but it doesn't print value at all on init. I also tried ng-bind directive but no luck.



Please assist me where I'm doing wrong. As far as i can estimate that $scope might conflicting with this (var controller = this;) in controller.



Also how can i add success/error class to input parent element based on response?



Thanks for reading my query and i appreciate your help in advance.










share|improve this question


















  • 1




    You need to assign a controller alias in ng-controller when not using $scope
    – charlietfl
    Nov 19 at 23:30












  • Can u make a plunkr with the code?
    – ppollono
    Nov 19 at 23:55










  • Thanks @charlietfl, by assinging controller alias my problem is resolved, though have to fix couple of more things.
    – Umair Razzaq
    Nov 20 at 5:37













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm trying to update button value on-click based $http responses. I want to change button value to Processing... while making $http request with ng-click function. And based on Success/Error response, need to update text Success and Try Again etc.



I'm using ui-router and I've different form elements distributed in different states, e.g. Email, User, Password etc.



In my View, I've following code in Email State.



<div ng-controller="RegisterEmailController">
<div class="form-group" style="position: relative;" ng-class="{ 'has-error': form.useremail.$dirty && form.useremail.$error.required && form.useremail.$invalid }">
<input type="email" name="useremail" id="useremail" ng-model="RegisterEmailController.userDetail.useremail" ng-required="true">
<span ng-show="form.useremail.$dirty && form.useremail.$error.required" class="help-block text-sm text-danger pl-4">Oops! Incorrect email address, or field is empty</span>
<span ng-hide="form.useremail.$dirty && form.useremail.$error.required" class="help-block d-block text-sm text-danger px-4">{{ErrorMsg}}</span>
</div>
<button type="button" ng-click="RegisterEmailController.nexStep()">{{buttonTxt}}</button>
</div>


In my Controller



var controller = this;
$scope.buttonTxt = 'Next Step';

controller.nexStep = function() {
$scope.buttonTxt = 'Processing...';
if ( validation_conditions ) {
$http({
method: "POST",
url: ApiURL,
headers: { "Content-Type": "application/json" },
data: getData
}).then(function success(response) {
$scope.buttonTxt = 'Success';
}, function error(response) {
$scope.buttonTxt = 'Try Again';
return;
});
} else {
$scope.buttonTxt = 'Try Again';
return;
}
}


With above code i can't be able to change button text on click, i tried with controller.buttonTxt as well but it doesn't print value at all on init. I also tried ng-bind directive but no luck.



Please assist me where I'm doing wrong. As far as i can estimate that $scope might conflicting with this (var controller = this;) in controller.



Also how can i add success/error class to input parent element based on response?



Thanks for reading my query and i appreciate your help in advance.










share|improve this question













I'm trying to update button value on-click based $http responses. I want to change button value to Processing... while making $http request with ng-click function. And based on Success/Error response, need to update text Success and Try Again etc.



I'm using ui-router and I've different form elements distributed in different states, e.g. Email, User, Password etc.



In my View, I've following code in Email State.



<div ng-controller="RegisterEmailController">
<div class="form-group" style="position: relative;" ng-class="{ 'has-error': form.useremail.$dirty && form.useremail.$error.required && form.useremail.$invalid }">
<input type="email" name="useremail" id="useremail" ng-model="RegisterEmailController.userDetail.useremail" ng-required="true">
<span ng-show="form.useremail.$dirty && form.useremail.$error.required" class="help-block text-sm text-danger pl-4">Oops! Incorrect email address, or field is empty</span>
<span ng-hide="form.useremail.$dirty && form.useremail.$error.required" class="help-block d-block text-sm text-danger px-4">{{ErrorMsg}}</span>
</div>
<button type="button" ng-click="RegisterEmailController.nexStep()">{{buttonTxt}}</button>
</div>


In my Controller



var controller = this;
$scope.buttonTxt = 'Next Step';

controller.nexStep = function() {
$scope.buttonTxt = 'Processing...';
if ( validation_conditions ) {
$http({
method: "POST",
url: ApiURL,
headers: { "Content-Type": "application/json" },
data: getData
}).then(function success(response) {
$scope.buttonTxt = 'Success';
}, function error(response) {
$scope.buttonTxt = 'Try Again';
return;
});
} else {
$scope.buttonTxt = 'Try Again';
return;
}
}


With above code i can't be able to change button text on click, i tried with controller.buttonTxt as well but it doesn't print value at all on init. I also tried ng-bind directive but no luck.



Please assist me where I'm doing wrong. As far as i can estimate that $scope might conflicting with this (var controller = this;) in controller.



Also how can i add success/error class to input parent element based on response?



Thanks for reading my query and i appreciate your help in advance.







javascript angularjs






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 23:18









Umair Razzaq

107215




107215








  • 1




    You need to assign a controller alias in ng-controller when not using $scope
    – charlietfl
    Nov 19 at 23:30












  • Can u make a plunkr with the code?
    – ppollono
    Nov 19 at 23:55










  • Thanks @charlietfl, by assinging controller alias my problem is resolved, though have to fix couple of more things.
    – Umair Razzaq
    Nov 20 at 5:37














  • 1




    You need to assign a controller alias in ng-controller when not using $scope
    – charlietfl
    Nov 19 at 23:30












  • Can u make a plunkr with the code?
    – ppollono
    Nov 19 at 23:55










  • Thanks @charlietfl, by assinging controller alias my problem is resolved, though have to fix couple of more things.
    – Umair Razzaq
    Nov 20 at 5:37








1




1




You need to assign a controller alias in ng-controller when not using $scope
– charlietfl
Nov 19 at 23:30






You need to assign a controller alias in ng-controller when not using $scope
– charlietfl
Nov 19 at 23:30














Can u make a plunkr with the code?
– ppollono
Nov 19 at 23:55




Can u make a plunkr with the code?
– ppollono
Nov 19 at 23:55












Thanks @charlietfl, by assinging controller alias my problem is resolved, though have to fix couple of more things.
– Umair Razzaq
Nov 20 at 5:37




Thanks @charlietfl, by assinging controller alias my problem is resolved, though have to fix couple of more things.
– Umair Razzaq
Nov 20 at 5:37












2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










Try this






var controller = function ($http) {
var validation_conditions
var ApiURL = 'google.com'
var getData = ''
this.buttonTxt = 'Next Step';

this.nexStep = function() {
this.buttonTxt = 'Processing...';
if ( validation_conditions ) {
$http({
method: "POST",
url: ApiURL,
headers: { "Content-Type": "application/json" },
data: getData
}).then(function success(response) {
this.buttonTxt = 'Success';
}, function error(response) {
this.buttonTxt = 'Try Again';
return;
});
} else {
this.buttonTxt = 'Try Again';
return;
}
}
}
controller.$inject = ['$http']

angular
.module('app', )
.controller('RegisterEmailController',controller);

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="RegisterEmailController as ctrl">
<div class="form-group" style="position: relative;" ng-class="{ 'has-error': form.useremail.$dirty && form.useremail.$error.required && form.useremail.$invalid }">
<input type="email" name="useremail" id="useremail" ng-model="RegisterEmailController.userDetail.useremail" ng-required="true">
<span ng-show="form.useremail.$dirty && form.useremail.$error.required" class="help-block text-sm text-danger pl-4">Oops! Incorrect email address, or field is empty</span>
<span ng-hide="form.useremail.$dirty && form.useremail.$error.required" class="help-block d-block text-sm text-danger px-4">{{ctrl.ErrorMsg}}</span>
</div>
<button type="button" ng-click="ctrl.nexStep()">{{ctrl.buttonTxt}}</button>
</div>








share|improve this answer





















  • Thanks @ppollono, my issue is resolved. Further can you please assist how can i add valid/error class to input based on success/error responses?
    – Umair Razzaq
    Nov 20 at 5:42










  • To be able to help you with this you need an endpoint to get the responses (success/error)
    – ppollono
    Nov 20 at 11:03










  • yes you're right, i was able to add conditional classes with the response i get. Thanks for following up (thumbs-up)
    – Umair Razzaq
    Nov 21 at 13:33


















up vote
1
down vote













Try to use:



<div ng-controller="RegisterEmailController as $registerEmail">


and then in button:



<button type="button" ng-click="RegisterEmailController.nexStep()">{{$registerEmail.buttonTxt}}</button>





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384017%2fangularjs-update-button-text-based-http-responses-ng-click%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    Try this






    var controller = function ($http) {
    var validation_conditions
    var ApiURL = 'google.com'
    var getData = ''
    this.buttonTxt = 'Next Step';

    this.nexStep = function() {
    this.buttonTxt = 'Processing...';
    if ( validation_conditions ) {
    $http({
    method: "POST",
    url: ApiURL,
    headers: { "Content-Type": "application/json" },
    data: getData
    }).then(function success(response) {
    this.buttonTxt = 'Success';
    }, function error(response) {
    this.buttonTxt = 'Try Again';
    return;
    });
    } else {
    this.buttonTxt = 'Try Again';
    return;
    }
    }
    }
    controller.$inject = ['$http']

    angular
    .module('app', )
    .controller('RegisterEmailController',controller);

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <div ng-app="app" ng-controller="RegisterEmailController as ctrl">
    <div class="form-group" style="position: relative;" ng-class="{ 'has-error': form.useremail.$dirty && form.useremail.$error.required && form.useremail.$invalid }">
    <input type="email" name="useremail" id="useremail" ng-model="RegisterEmailController.userDetail.useremail" ng-required="true">
    <span ng-show="form.useremail.$dirty && form.useremail.$error.required" class="help-block text-sm text-danger pl-4">Oops! Incorrect email address, or field is empty</span>
    <span ng-hide="form.useremail.$dirty && form.useremail.$error.required" class="help-block d-block text-sm text-danger px-4">{{ctrl.ErrorMsg}}</span>
    </div>
    <button type="button" ng-click="ctrl.nexStep()">{{ctrl.buttonTxt}}</button>
    </div>








    share|improve this answer





















    • Thanks @ppollono, my issue is resolved. Further can you please assist how can i add valid/error class to input based on success/error responses?
      – Umair Razzaq
      Nov 20 at 5:42










    • To be able to help you with this you need an endpoint to get the responses (success/error)
      – ppollono
      Nov 20 at 11:03










    • yes you're right, i was able to add conditional classes with the response i get. Thanks for following up (thumbs-up)
      – Umair Razzaq
      Nov 21 at 13:33















    up vote
    1
    down vote



    accepted










    Try this






    var controller = function ($http) {
    var validation_conditions
    var ApiURL = 'google.com'
    var getData = ''
    this.buttonTxt = 'Next Step';

    this.nexStep = function() {
    this.buttonTxt = 'Processing...';
    if ( validation_conditions ) {
    $http({
    method: "POST",
    url: ApiURL,
    headers: { "Content-Type": "application/json" },
    data: getData
    }).then(function success(response) {
    this.buttonTxt = 'Success';
    }, function error(response) {
    this.buttonTxt = 'Try Again';
    return;
    });
    } else {
    this.buttonTxt = 'Try Again';
    return;
    }
    }
    }
    controller.$inject = ['$http']

    angular
    .module('app', )
    .controller('RegisterEmailController',controller);

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <div ng-app="app" ng-controller="RegisterEmailController as ctrl">
    <div class="form-group" style="position: relative;" ng-class="{ 'has-error': form.useremail.$dirty && form.useremail.$error.required && form.useremail.$invalid }">
    <input type="email" name="useremail" id="useremail" ng-model="RegisterEmailController.userDetail.useremail" ng-required="true">
    <span ng-show="form.useremail.$dirty && form.useremail.$error.required" class="help-block text-sm text-danger pl-4">Oops! Incorrect email address, or field is empty</span>
    <span ng-hide="form.useremail.$dirty && form.useremail.$error.required" class="help-block d-block text-sm text-danger px-4">{{ctrl.ErrorMsg}}</span>
    </div>
    <button type="button" ng-click="ctrl.nexStep()">{{ctrl.buttonTxt}}</button>
    </div>








    share|improve this answer





















    • Thanks @ppollono, my issue is resolved. Further can you please assist how can i add valid/error class to input based on success/error responses?
      – Umair Razzaq
      Nov 20 at 5:42










    • To be able to help you with this you need an endpoint to get the responses (success/error)
      – ppollono
      Nov 20 at 11:03










    • yes you're right, i was able to add conditional classes with the response i get. Thanks for following up (thumbs-up)
      – Umair Razzaq
      Nov 21 at 13:33













    up vote
    1
    down vote



    accepted







    up vote
    1
    down vote



    accepted






    Try this






    var controller = function ($http) {
    var validation_conditions
    var ApiURL = 'google.com'
    var getData = ''
    this.buttonTxt = 'Next Step';

    this.nexStep = function() {
    this.buttonTxt = 'Processing...';
    if ( validation_conditions ) {
    $http({
    method: "POST",
    url: ApiURL,
    headers: { "Content-Type": "application/json" },
    data: getData
    }).then(function success(response) {
    this.buttonTxt = 'Success';
    }, function error(response) {
    this.buttonTxt = 'Try Again';
    return;
    });
    } else {
    this.buttonTxt = 'Try Again';
    return;
    }
    }
    }
    controller.$inject = ['$http']

    angular
    .module('app', )
    .controller('RegisterEmailController',controller);

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <div ng-app="app" ng-controller="RegisterEmailController as ctrl">
    <div class="form-group" style="position: relative;" ng-class="{ 'has-error': form.useremail.$dirty && form.useremail.$error.required && form.useremail.$invalid }">
    <input type="email" name="useremail" id="useremail" ng-model="RegisterEmailController.userDetail.useremail" ng-required="true">
    <span ng-show="form.useremail.$dirty && form.useremail.$error.required" class="help-block text-sm text-danger pl-4">Oops! Incorrect email address, or field is empty</span>
    <span ng-hide="form.useremail.$dirty && form.useremail.$error.required" class="help-block d-block text-sm text-danger px-4">{{ctrl.ErrorMsg}}</span>
    </div>
    <button type="button" ng-click="ctrl.nexStep()">{{ctrl.buttonTxt}}</button>
    </div>








    share|improve this answer












    Try this






    var controller = function ($http) {
    var validation_conditions
    var ApiURL = 'google.com'
    var getData = ''
    this.buttonTxt = 'Next Step';

    this.nexStep = function() {
    this.buttonTxt = 'Processing...';
    if ( validation_conditions ) {
    $http({
    method: "POST",
    url: ApiURL,
    headers: { "Content-Type": "application/json" },
    data: getData
    }).then(function success(response) {
    this.buttonTxt = 'Success';
    }, function error(response) {
    this.buttonTxt = 'Try Again';
    return;
    });
    } else {
    this.buttonTxt = 'Try Again';
    return;
    }
    }
    }
    controller.$inject = ['$http']

    angular
    .module('app', )
    .controller('RegisterEmailController',controller);

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <div ng-app="app" ng-controller="RegisterEmailController as ctrl">
    <div class="form-group" style="position: relative;" ng-class="{ 'has-error': form.useremail.$dirty && form.useremail.$error.required && form.useremail.$invalid }">
    <input type="email" name="useremail" id="useremail" ng-model="RegisterEmailController.userDetail.useremail" ng-required="true">
    <span ng-show="form.useremail.$dirty && form.useremail.$error.required" class="help-block text-sm text-danger pl-4">Oops! Incorrect email address, or field is empty</span>
    <span ng-hide="form.useremail.$dirty && form.useremail.$error.required" class="help-block d-block text-sm text-danger px-4">{{ctrl.ErrorMsg}}</span>
    </div>
    <button type="button" ng-click="ctrl.nexStep()">{{ctrl.buttonTxt}}</button>
    </div>








    var controller = function ($http) {
    var validation_conditions
    var ApiURL = 'google.com'
    var getData = ''
    this.buttonTxt = 'Next Step';

    this.nexStep = function() {
    this.buttonTxt = 'Processing...';
    if ( validation_conditions ) {
    $http({
    method: "POST",
    url: ApiURL,
    headers: { "Content-Type": "application/json" },
    data: getData
    }).then(function success(response) {
    this.buttonTxt = 'Success';
    }, function error(response) {
    this.buttonTxt = 'Try Again';
    return;
    });
    } else {
    this.buttonTxt = 'Try Again';
    return;
    }
    }
    }
    controller.$inject = ['$http']

    angular
    .module('app', )
    .controller('RegisterEmailController',controller);

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <div ng-app="app" ng-controller="RegisterEmailController as ctrl">
    <div class="form-group" style="position: relative;" ng-class="{ 'has-error': form.useremail.$dirty && form.useremail.$error.required && form.useremail.$invalid }">
    <input type="email" name="useremail" id="useremail" ng-model="RegisterEmailController.userDetail.useremail" ng-required="true">
    <span ng-show="form.useremail.$dirty && form.useremail.$error.required" class="help-block text-sm text-danger pl-4">Oops! Incorrect email address, or field is empty</span>
    <span ng-hide="form.useremail.$dirty && form.useremail.$error.required" class="help-block d-block text-sm text-danger px-4">{{ctrl.ErrorMsg}}</span>
    </div>
    <button type="button" ng-click="ctrl.nexStep()">{{ctrl.buttonTxt}}</button>
    </div>





    var controller = function ($http) {
    var validation_conditions
    var ApiURL = 'google.com'
    var getData = ''
    this.buttonTxt = 'Next Step';

    this.nexStep = function() {
    this.buttonTxt = 'Processing...';
    if ( validation_conditions ) {
    $http({
    method: "POST",
    url: ApiURL,
    headers: { "Content-Type": "application/json" },
    data: getData
    }).then(function success(response) {
    this.buttonTxt = 'Success';
    }, function error(response) {
    this.buttonTxt = 'Try Again';
    return;
    });
    } else {
    this.buttonTxt = 'Try Again';
    return;
    }
    }
    }
    controller.$inject = ['$http']

    angular
    .module('app', )
    .controller('RegisterEmailController',controller);

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <div ng-app="app" ng-controller="RegisterEmailController as ctrl">
    <div class="form-group" style="position: relative;" ng-class="{ 'has-error': form.useremail.$dirty && form.useremail.$error.required && form.useremail.$invalid }">
    <input type="email" name="useremail" id="useremail" ng-model="RegisterEmailController.userDetail.useremail" ng-required="true">
    <span ng-show="form.useremail.$dirty && form.useremail.$error.required" class="help-block text-sm text-danger pl-4">Oops! Incorrect email address, or field is empty</span>
    <span ng-hide="form.useremail.$dirty && form.useremail.$error.required" class="help-block d-block text-sm text-danger px-4">{{ctrl.ErrorMsg}}</span>
    </div>
    <button type="button" ng-click="ctrl.nexStep()">{{ctrl.buttonTxt}}</button>
    </div>






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 20 at 0:19









    ppollono

    2,36111425




    2,36111425












    • Thanks @ppollono, my issue is resolved. Further can you please assist how can i add valid/error class to input based on success/error responses?
      – Umair Razzaq
      Nov 20 at 5:42










    • To be able to help you with this you need an endpoint to get the responses (success/error)
      – ppollono
      Nov 20 at 11:03










    • yes you're right, i was able to add conditional classes with the response i get. Thanks for following up (thumbs-up)
      – Umair Razzaq
      Nov 21 at 13:33


















    • Thanks @ppollono, my issue is resolved. Further can you please assist how can i add valid/error class to input based on success/error responses?
      – Umair Razzaq
      Nov 20 at 5:42










    • To be able to help you with this you need an endpoint to get the responses (success/error)
      – ppollono
      Nov 20 at 11:03










    • yes you're right, i was able to add conditional classes with the response i get. Thanks for following up (thumbs-up)
      – Umair Razzaq
      Nov 21 at 13:33
















    Thanks @ppollono, my issue is resolved. Further can you please assist how can i add valid/error class to input based on success/error responses?
    – Umair Razzaq
    Nov 20 at 5:42




    Thanks @ppollono, my issue is resolved. Further can you please assist how can i add valid/error class to input based on success/error responses?
    – Umair Razzaq
    Nov 20 at 5:42












    To be able to help you with this you need an endpoint to get the responses (success/error)
    – ppollono
    Nov 20 at 11:03




    To be able to help you with this you need an endpoint to get the responses (success/error)
    – ppollono
    Nov 20 at 11:03












    yes you're right, i was able to add conditional classes with the response i get. Thanks for following up (thumbs-up)
    – Umair Razzaq
    Nov 21 at 13:33




    yes you're right, i was able to add conditional classes with the response i get. Thanks for following up (thumbs-up)
    – Umair Razzaq
    Nov 21 at 13:33












    up vote
    1
    down vote













    Try to use:



    <div ng-controller="RegisterEmailController as $registerEmail">


    and then in button:



    <button type="button" ng-click="RegisterEmailController.nexStep()">{{$registerEmail.buttonTxt}}</button>





    share|improve this answer

























      up vote
      1
      down vote













      Try to use:



      <div ng-controller="RegisterEmailController as $registerEmail">


      and then in button:



      <button type="button" ng-click="RegisterEmailController.nexStep()">{{$registerEmail.buttonTxt}}</button>





      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        Try to use:



        <div ng-controller="RegisterEmailController as $registerEmail">


        and then in button:



        <button type="button" ng-click="RegisterEmailController.nexStep()">{{$registerEmail.buttonTxt}}</button>





        share|improve this answer












        Try to use:



        <div ng-controller="RegisterEmailController as $registerEmail">


        and then in button:



        <button type="button" ng-click="RegisterEmailController.nexStep()">{{$registerEmail.buttonTxt}}</button>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 at 23:50









        uamanager

        1557




        1557






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384017%2fangularjs-update-button-text-based-http-responses-ng-click%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'