简体   繁体   中英

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?

You don't want to navigate around "views" by URLs in Angular.

Take a look at ui-router and use $stateS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM