【发布时间】:2015-10-19 06:14:44
【问题描述】:
这是我的模块部分。我已经编写了列出ccategory的路由,添加类别和编辑类别。
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 中的数组中获取了单个对象多变的。 现在我正在尝试在编辑页面上打印这个单个对象值,但这些值没有显示在编辑页面上。
【问题讨论】:
标签: javascript php jquery angularjs routes