javascript - 如何在 Angular js中获取 Controller 的路由值

标签 javascript php angularjs

我是 Angular js 新手,想在博客网站中进行简单的增删改查操作,我不知道如何从路由获取值到 Controller 以查看表单中的特定记录进行编辑

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;
})

关于javascript - 如何在 Angular js中获取 Controller 的路由值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30234230/

相关文章:

php - 插入数据作为时间点,检索数据作为时间范围

带过滤器的php登录用户名和密码

angularjs - 从 Controller 重定向到ons-template

css - ui-sref-active ="active"在我的导航栏菜单中不起作用

php - 当对同一页面进行表单操作时,保留页面位置?

php - 如何让ajax javascript在按下回车键时工作

javascript - 如何在Firefox Web扩展中使用cloneInto?

javascript - 使用 Reactjs 将 Express req 和 res 数据传递给客户端

php - 尝试在 Laravel 中删除行时出现 “Call to undefined method stdClass::delete()” 错误

javascript - 选择隐藏的元素后 Tabindex 未使用正确的顺序