How to get route value to controller in angular js

Rahul Saxena

I am new in angular js, want to make simple crud operation in blog site, I dont know how to get the value from route to the controller for view the particular record in the form to edit

Controller.js file

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

});

Appreciate if anyone help me.. Thanks

Zee

You need to use routeParams

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

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

how to inject a value in an angular controller

分類Dev

How to get drop down value in Controller in MVC

分類Dev

How to register apicontroller & controller route

分類Dev

How to get an absolute Url by a route name in Angular 2?

分類Dev

Angular js partial controller

分類Dev

Nuxt.js: how to track the value of $route.params.someKey?

分類Dev

Laravel 5.7 Passing a value to a route in a controller

分類Dev

How to show Angular controller data based on specific value

分類Dev

How do I add a controller to a module in Angular JS

分類Dev

How to pass json data from C# controller to angular js?

分類Dev

How to get the value from angular material checkbox

分類Dev

How to return value using $q in angular js?

分類Dev

How the controller in angular is called?

分類Dev

Angular.js "Controller as ..." + $ scope。$ on

分類Dev

Angular JS controller throwing error

分類Dev

How to test an ExpressJS route and 'controller' separately

分類Dev

How to send value with route - reactjs

分類Dev

Execute route if only the local Angular App calls it true the controller

分類Dev

Angular 2 get current route in guard

分類Dev

Angular 2 get current route in guard

分類Dev

Angular 2 get current route in guard

分類Dev

Get current parameter in route - Angular 4

分類Dev

Angular service, $http.get() with a route param?

分類Dev

Angular route results in 404 - cannot GET

分類Dev

No route found for "GET /Index" when generating Symfony controller

分類Dev

Angular get value in URL

分類Dev

How to use this angular factory in controller?

分類Dev

Angular 2: How to get the selected value from different options of a form?

分類Dev

How to get and set value in nested form fields in angular2?

Related 関連記事

  1. 1

    how to inject a value in an angular controller

  2. 2

    How to get drop down value in Controller in MVC

  3. 3

    How to register apicontroller & controller route

  4. 4

    How to get an absolute Url by a route name in Angular 2?

  5. 5

    Angular js partial controller

  6. 6

    Nuxt.js: how to track the value of $route.params.someKey?

  7. 7

    Laravel 5.7 Passing a value to a route in a controller

  8. 8

    How to show Angular controller data based on specific value

  9. 9

    How do I add a controller to a module in Angular JS

  10. 10

    How to pass json data from C# controller to angular js?

  11. 11

    How to get the value from angular material checkbox

  12. 12

    How to return value using $q in angular js?

  13. 13

    How the controller in angular is called?

  14. 14

    Angular.js "Controller as ..." + $ scope。$ on

  15. 15

    Angular JS controller throwing error

  16. 16

    How to test an ExpressJS route and 'controller' separately

  17. 17

    How to send value with route - reactjs

  18. 18

    Execute route if only the local Angular App calls it true the controller

  19. 19

    Angular 2 get current route in guard

  20. 20

    Angular 2 get current route in guard

  21. 21

    Angular 2 get current route in guard

  22. 22

    Get current parameter in route - Angular 4

  23. 23

    Angular service, $http.get() with a route param?

  24. 24

    Angular route results in 404 - cannot GET

  25. 25

    No route found for "GET /Index" when generating Symfony controller

  26. 26

    Angular get value in URL

  27. 27

    How to use this angular factory in controller?

  28. 28

    Angular 2: How to get the selected value from different options of a form?

  29. 29

    How to get and set value in nested form fields in angular2?

ホットタグ

アーカイブ