[英]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.