Caleb Prenger Caleb Prenger - 10 months ago 38
AngularJS Question

Angular routeProvider and passing scopes

I am using routeProvider to create deep linking in my app. My issue is I need to have multiple levels. So lets say i have a products page the link would be:

$scope.products contains all of the products. Once clicked on the product, I need to be able to keep $scope.products and change the URL to the '/1' being the id of the product.


on your products controller create a function and call it to navigate to the edit page something like this...

$scope.edit = function (data) {
        $window.location.href = '#/Products/Edit' + '?id=' +;

on your edit controller call $routeParams and load the object from your api, as it might have changed

function loadProduct()
        productEditFactory.getProduct($ (response) {
            $scope.product =;
        }, function (response) {


    if ($
    else {
        $scope.editMode = false;

you also need to update your $routeProvider definition with something like this...

.when('/Product/Edit', {
        templateUrl: function (params) { return 'Products/Edit?id=' + ; }