Search code examples
angularjstwitter-bootstrapmodel-view-controllercontrollerwindow

$window.location.href is undefined with angularjs


I programme an application in ASP.NET MVC6, angularjs and Bootstap. I want reload a page after bootstrap modal closing. To do this, I use $window.location.href but it's undefined.

This is my method in angular Controller:

 angular
    .module('LSapp')
    .controller('CustomersCtrl', CustomersCtrl);

CustomersCtrl.$inject = ['$scope', '$http', '$location', '$modal', '$templateCache', '$window'];

function CustomersCtrl($scope, $http, $location, $modal, $window) {
     $scope.edit = function(id)
    {
        var customer = getCustomer(id);
        console.log('Customer => FirstName : ' + customer.FirstName);
        var reqEditCustomer = $http({ url: '/api/customers/', dataType: 'json', method: 'PUT', data: JSON.stringify(customer), contentType: 'application/json; charset=utf-8' });
        reqEditCustomer.success(function (dataResult) {
            $scope.customer = dataResult;
            $scope.cancel();       
        });
        $scope.customers = getListCustomers();
        $window.location.href = '/';
    }
}

All runs except the redirection.

I hope someone can help me . Any help is welcome.


Solution

  • I solved the problem by using ui.router instead of ng -router.