Search code examples
angularjseditloaddata

How to GET on loadData with a ID in Angularjs


Hello I am new to AngularJs.

I like to get this edit_task with its id:

http://localhost:8080/edit_task/5629499534213120

I don't know how to get the ID into my function loadData().

This is a part of the app.js

$scope.editTask = function (id) {
    var config = {
        headers: {
            "CommandType": "editTask"
        }
    };


    function loadData() {
        $http.get("http://localhost:8080/edit_task/" + id ,data ,config).success(function (data) {
            $scope.tasks = data;
        });
    };

I couldend find any example ore documentation on this

Hope someone will help me on my way into Angularjs?


Solution

  • In your app.js (or wherever you define your routes), define the id:

    .when('/edit_task/:taskid', {
                templateUrl: 'TEMPLATEURL',
                controller: 'CONTROLLER_NAME',
            })
    

    Then, in the controller inject $routeParams and query for the taskid:

    APP.controller('CONTROLLER_NAME', function ($scope, $routeParams) {
         var taskId = $routeParams.taskid;
    });