簡體   English   中英

如何在Angular JS中獲取到控制器的路由值

[英]How to get route value to controller in angular js

我是angular js的新手,想在博客站點中進行簡單的crud操作,我不知道如何從路由到控制器中獲取值以查看表單中的特定記錄以進行編輯

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**

});

感謝有人幫助我..謝謝

您需要使用routeParams

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM