Javascript 如何在angular js中获取控制器的路由值
我是angular js的新手,想在博客站点中进行简单的crud操作,我不知道如何从路由到控制器获取值,以便查看表单中要编辑的特定记录 Controller.js文件Javascript 如何在angular js中获取控制器的路由值,javascript,php,angularjs,Javascript,Php,Angularjs,我是angular js的新手,想在博客站点中进行简单的crud操作,我不知道如何从路由到控制器获取值,以便查看表单中要编辑的特定记录 Controller.js文件 var myApp = angular.module("blogapp",[]); myApp.config(['$routeProvider',function($routeProvider){ $routeProvider .when('/home',{ templateUrl:'
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**
});
如果有人帮助我,我将不胜感激。。谢谢您需要使用
Blogid正在路由中。。我评论代码检查我的问题解决了谢谢。。。你能告诉我一件事吗,我想用这个id来获取记录,所以我用这个:$http.get('page.php?id='+Blogid);//对还是wrong@RahulSaxena为此,请看这个
myApp.controller('editcontroller',function ($scope,$http,$routeParams){
$scope.Blogid = $routeParams.Blogid;
})