简体   繁体   中英

Simple edit functionality is not working in angular js using routes?

This is my module part.That I have written the route for listing the ccategory,add the category and edit category.

var my_app= angular.module('myApp', ['ngRoute','myApp.controllers','myApp.factory']);
my_app.value("category_list",0);
my_app.value("single_category",0);
my_app. config(['$routeProvider', function ($routeProvider) {       

        $routeProvider.when('/category', {templateUrl: 'category/list.php', controller: 'category',activetab: 'category'});     
        $routeProvider.when('/add-category', {templateUrl: 'category/add.php', controller: 'category',activetab: 'category'});
        $routeProvider.when('/edit-category/:param', {templateUrl: 'category/add.php', activetab: 'category'});
        $routeProvider.otherwise({redirectTo: '/dashboard'});
    }]);

This is my controller

angular.module("myApp.controllers",[])

        .controller("users",function($scope,$location){           

        })
        .controller("category",function($scope,$location,$route,dataFactory,$routeParams,category_list,single_category){    
            $scope.param = $routeParams.param; 
getCategory();
            function getCategory() {                
                dataFactory.getCategoryList()
                    .success(function (msg) {
                        $scope.catagories=msg;
                category_list=msg;
                    })
                    .error(function (error) {
                        $scope.status = 'Unable to load customer data: ' + error.message;
                    });
            }
 $scope.editCategory=function(mid){
                single_category=category_list[mid];
                alert(single_category);
               $scope.category_name=category_list[mid].category_name;
               console.log(category_list[mid].category_name);
               //alert($scope.category.category_name);
               $location.path("/edit-category/"+mid);
            }

})

Here in this controller,there is one function getCategory().Using this function I got the category json array.Now after clicking on edit button from view.I got that single object from array in editCategory() function single_category in this variable. Now I am trying to print this single object value on edit page but the values are not showing on edit page.

Your edit-category route does not include the category controller, so you wont be able to access the scope or any functions defined in it.

$routeProvider.when('/edit-category/:param', {
    templateUrl: 'category/add.php',
    controller: 'category',
    activetab: 'category'
});

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