Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • jacob phillips 130 posts 372 karma points
    Jan 16, 2015 @ 06:53
    jacob phillips

    Get the current node into a service


    I am going through the various Angular/WebApi examples for creating Umbraco service...and watching some Angular tutorials...getting there...

    So I got this example working..

    And I have moved onto this one which demonstrates CRUD operations:

    Could someone more experienced tell me...

    If I create a service that does something in relation to the document that it runs can I pass in the node id of this document?

    So for example, consider in "UmbracoAngularBackofficePages" project, in PersonApiController.cs we got:

    public Person GetById(int id)
     var query = new Sql().Select("*").From("people").Where<Person>(x => x.Id == id);
     return DatabaseContext.Database.Fetch<Person>(query).FirstOrDefault();

    and then in person.resource.js we got:

    getById: function (id) {
       return $http.get("backoffice/Example/PersonApi/GetById?id=" + id);

    In the first example I went through, there is a personpicker.controller.js file:

        .controller("My.PersonPickerController", function($scope, personResource){
                $scope.people =;

    So instead of calling getAll(), if I wanted to get getById(with node id that this is running on), how can I make it so that whatever node I put this service on, it use the current id?

    I realize it might not make sense why I would want to do exactly that, but I'm using these examples as a recipe to do something else, and I need to start off by passing in this current id. I can't see how to do it.

  • jacob phillips 130 posts 372 karma points
    Jan 16, 2015 @ 16:59
    jacob phillips

    Hmmm, I guess maybe in my .cs controller, in the method I want, I could just use umbraco node factory..something like...

    Node node = Node.GetCurrent();
    var query = new Sql().Select("*").From("myTable").Where<MyCustomObject>(x => x.Id == node.Id);

    So,. it's not really about getting the context from the Angular at all..?

Please Sign in or register to post replies

Write your reply to: