2015-05-14 106 views
1

我是新的角js,想在博客網站做簡單的crud操作,我不知道如何從路由獲取值到控制器查看特定記錄在表單編輯如何獲得路由價值的角度js控制器

Controller.js文件

var myApp = angular.module("blogapp",[]); 

    myApp.config(['$routeProvider',function($routeProvider){ 

    $routeProvider 
     .when('/home',{ 
     templateUrl:'home.html', 
     controller:'blogcontroller' 
     }) 
     .when('/list',{ 
     templateUrl:'list.html', 
     controller:'blogcontroller' 

     }) 
     .when('/add',{ 

     templateUrl:'add.html', 
     controller:'addcontroller' 
     }) 
     .when('/edit/:Blogid',{ **// Want to get this Blogid** 

     templateUrl:'edit.html', 
     controller:'editcontroller' 
     }) 
     .otherwise({ 
     redirectTo:'/home' 
     }); 

    }]); 


myApp.controller('blogcontroller',function ($scope,$http){ 

    $http({method: 'GET' , url: 'getallblog.php'}).success(function(data){ 
     $scope.allblog = data; 
    }); 

// DELETE blog HERE 
$scope.removeRow= function(id){ 



    $http.post("removeblog.php",{'id' : id}).success(function(data,status,headers,config){ 
     window.location='index.html'; 
     console.log("Deleted Successfully"); 

    }); 
    }; 

// delete blog code ends here 


    }); 


myApp.controller('addcontroller',function ($scope,$http){ 





    /// New Post Here 
    $scope.new_post =function(){ 



    $http.post("addblog.php" ,{'title' : $scope.title ,'description' : $scope.description }).success(function(data,status,headers,config){ 
     window.location='index.html'; 
     console.log("inserted Successfully"); 
    }); 
    }; 



    // New Post ends Here 

}); 

myApp.controller('editcontroller',function ($scope,$http,$routeParams){ 

**// Want to get here this Blogid** 

}); 

感激,如果有人幫我..謝謝

+0

Blogid的路線。我評論的代碼檢查 –

回答

2

您需要使用routeParams

myApp.controller('editcontroller',function ($scope,$http,$routeParams){ 
    $scope.Blogid = $routeParams.Blogid; 
}) 
+0

好我的問題就解決了感謝...你能告訴我,我想用這個ID爲獲得創紀錄的一個東西,所以使用該即時通訊: $ http.get('page.php?id ='+ Blogid); //對或錯 –

+0

@RahulSaxena對於這一點看到這[如何傳遞數據在get。](http://stackoverflow.com/questions/13760070/angularjs-passing-data-to-http-get-request) – Zee

相關問題