繁体   English   中英

简单的编辑功能在使用路由的Angular JS中不起作用?

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

这是我的模块部分。我写了列出类别,添加类别和编辑类别的路线。

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'});
    }]);

这是我的控制器

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);
            }

})

在此控制器中,有一个函数getCategory()。使用此函数,我获得了类别json数组。现在从视图中单击编辑按钮后。我在此变量的editCategory()函数single_category中从数组中获得了单个对象。 现在,我尝试在编辑页面上打印此单个对象的值,但是这些值未显示在编辑页面上。

您的编辑类别路由不包含类别控制器,因此您将无法访问范围或其中定义的任何功能。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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