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

1
  • Blogid in route .. I comment the code check it Commented May 14, 2015 at 9:53

1 Answer 1

3

You need to use routeParams

myApp.controller('editcontroller',function ($scope,$http,$routeParams){
     $scope.Blogid = $routeParams.Blogid;
})
Sign up to request clarification or add additional context in comments.

2 Comments

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
@RahulSaxena For that see this How to pass data in get.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.