2

I have a simple code here and got stuck in passing the parameter. Here is the code:

route.js

function config($routeProvider) {
    $routeProvider
    .when('/edit/:id', {
        controller: 'UpdateTodoCtrl',
        templateUrl: 'app/views/edit-todo.html'
    });
}

index.html

<div ng-controller="SomeOtherCtrl">
<table>
<tr ng-repeat="t in todos">
<a href="#/edit/{{ t.id }}">{{ t.name }}</a>
</tr>
</table>
</div

Controller

function UpdateTodoCtrl($http, $scope) {

    function init() {
        $scope.todos = null;
        $scope.loading = true;

        $http.get('app/endpoints/edit-todo.php', {
            params: { todoId:  //how to get the id paramter }
        });
    }

}

As you can ee in the controller, I commented out the part of my problem. How can I possibly pass the id in my url using $http.get? Thank you.

1 Answer 1

2

Your :id is a route parameter so you can do like this :

function UpdateTodoCtrl($http, $scope, $routeParams) {

    function init() {
        $scope.todos = null;
        $scope.loading = true;

        $http.get('app/endpoints/edit-todo.php', {
            params: { todoId: $routeParams.id }
        });
    }

}
Sign up to request clarification or add additional context in comments.

2 Comments

Oh my God I forget about this. Thank you.
Don't forget to accept the answer if it solves your problem ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.