Copied to clipboard

Flag this post as spam?

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


  • Ferry To 3 posts 83 karma points
    Jul 24, 2015 @ 10:42
    Ferry To
    0

    Loading data into a template/view

    Hello all, I am new to Umbraco and not familiar with AngularJS. What I want to do is to load and display data from a table reside in Umbraco database. I can make a custom property editor successfully and I can retrieve my data from browser directly at /umbraco/My/MessageApi/GetAll, however I do not know how could I load the result into a view/template.

    I tried to follow the way to put code like below into my template but seems angular javascript didn't load.

    <div ng-controller="My.MessageController">
    <ul>
        <li ng-repeat="message in messages">
            <a href ng-click="model.value = message.content">{{message.content}}</a>
        </li>
    </ul>
    

    angular.module("umbraco")
    .controller("My.MessageController", function($scope, messageResource){
        messageResource.getAll().then(function(response){
            $scope.messages = response.data;
        });
    });
    
    angular.module('umbraco.resources').factory('messageResource', 
    function($q, $http) {
        return {
            getAll: function () {
                return  $http.get("My/MessageApi/GetAll");
            }
        };
    }
    

    );

    Can someone provide me a sample/tutorial for that?

    Thanks!

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 24, 2015 @ 11:13
    Dennis Aaen
    100

    Hi Ferry,

    Perhaps this video from Aptitude https://www.aptitude.co.uk/videos/using-custom-tables-data-in-umbraco/ can help you to find out how to get data from from a table reside in Umbraco database and show it in a template / view.

    Hope this helps,

    /Dennis

  • Ferry To 3 posts 83 karma points
    Jul 24, 2015 @ 18:49
    Ferry To
    0

    Hey Dennis,

    Thanks so much! The video is helpful. I can get the data from local database. So I don't need to write a controller first right? Now I want to learn further that how could I load data from external source like a WebAPI call which will return JSON? Is it possible to use the AngularJS approach for the doing the same in the video? :)

Please Sign in or register to post replies

Write your reply to:

Draft