mercredi 15 juin 2016

AngularJs how to switch from one view to another from a controller

I'm a new programmer in angularJs. I'm implemeting a simple CRUD application the display a list of client. from the list of clients, i have a "Add Client" button that allow to move to AddClient View. after clicking on save button from addClientView, i would like to send the request to save the client ans then, back on the list of client

here is my function in my app.js that handle the save of client:

    $scope.addClient = function(isValid) {
    if (!isValid) {
        $scope.displayValidationError = true;
        return;
    }

    var url = "/myApp/clients/add";

    var config = {
        headers : {
            'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'
        }
    };

    $http.post(url, $.param($scope.client), config).success(
            function(data) {
               var urlWhereToBack = "/myApp/clients/list";
               //here code to launch this url and switch to the list of client
               ........
               ........
            }).error(function(data, status, headers, config) {
        $scope.handleRequestError(status);
    });
};

so, after the save of client, i want to launch the url "/myApp/clients/list" to back to yhe list of client

how can i do it please?

Aucun commentaire:

Enregistrer un commentaire