2

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

Rahul Saxena
  • 465
  • 4
  • 15

1 Answers1

3

You need to use routeParams

myApp.controller('editcontroller',function ($scope,$http,$routeParams){
     $scope.Blogid = $routeParams.Blogid;
})
Zee
  • 8,420
  • 5
  • 36
  • 58
  • Ok my problem is solved thanks... Can you please tell me one thing that i want to use this id for getting the record so i m using this: $http.get('page.php?id=' + Blogid); // right or wrong – Rahul Saxena May 14 '15 at 10:03
  • @RahulSaxena For that see this [How to pass data in get.](http://stackoverflow.com/questions/13760070/angularjs-passing-data-to-http-get-request) – Zee May 14 '15 at 10:10