Copied to clipboard

Flag this post as spam?

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


  • Dron 13 posts 33 karma points
    Mar 22, 2016 @ 12:02
    Dron
    0

    AngularJS $http.get not working

    Hi!

    I'm trying to extend Umbraco backend and need to send request to the custom controller form AngularJS.

    What I've done is:

        angular.module('AddAnswerModule', [])
            .controller('AddAnswerController', AddAnswerController)
    {
    
        function AddAnswerController() {
        }
    
        AddAnswerController.prototype.greet = function ($scope, $http) {
            alert(this.answer); //making suer it is working (yes, it is)
            $a = $http.get("http://google.com"); //here the execution stops
            alert($a);
        };    
    }
    

    I call alert especially for making sure contorller function is being called. Indeed it is working. But calling $http.get - stops all exectution. I have tried different variants, but no luck. In the sample code I'm calling google just to be sure this page is accessable.

    Can you, please, tell, what is wrong here and how can I cann $http.get inside Umbraco AngularJS controller?

    Thank you.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 23, 2016 @ 10:10
    Jan Skovgaard
    0

    Hi Dronone

    What is it that you're trying to build?

    I think that it maybe a good idea to have a look at the Angularjs workbook for Umbraco to see how you can make custom controllers, services etc. in Umbraco https://github.com/umbraco/AngularWorkbook and perhaps you can find more useful information here https://our.umbraco.org/documentation/Extending/Property-Editors/

    Since google does not return any data like xml or json you're probably getting an error in your browsers console log. Perhaps have a read on the $http provider here too - https://docs.angularjs.org/api/ng/service/$http

    Hope this helps.

    /Jan

  • Dron 13 posts 33 karma points
    Mar 23, 2016 @ 10:52
    Dron
    0

    Hi Jan!

    Many thanks for your help. Having read that Angular samples for umbraco I made everything working at one :)

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 23, 2016 @ 10:55
    Jan Skovgaard
    0

    Hi Dron

    Happy to hear you managed to get it all working - Care to share your solutions so others might benefit from your learnings too should they come across this post :)

    /Jan

  • Dron 13 posts 33 karma points
    Mar 23, 2016 @ 11:04
    Dron
    0

    Well, that's really easy having read that books you have shared.

    What is needed to know is that we need to use 'umbraco' module.

    So may use this like:

    angular.module("umbraco").controller("AddAnswerController", function ($http) { $a = $http.get("..."); //will work now });

Please Sign in or register to post replies

Write your reply to:

Draft