Copied to clipboard

Flag this post as spam?

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


  • Kim Nedergaard 37 posts 144 karma points
    Oct 07, 2014 @ 20:38
    Kim Nedergaard
    0

    Angular calling a function with parameter

    I've started playing around with Angular and extending the backend.

    My first attempt is a Google Map data type, where I type in an address and the marker pops up. Inspired by this tutorial: http://www.netaddicts.be/umbraco/enabling-google-maps-in-v7/ ( Awesome tutorial - really helped me alot, on getting started :)

    And now to my problem - I want to attach an id to my input field, where I use the {{model.alias}} to get a unique id in case of my property editor should be used multiple times on same node.

    But I can't seem to parse my {{model.alias}} to my function in my controller - it just returns "undefined".

    My view:

    <div ng-controller="GMaps.GoogleMapsController" class="umb-editor umb-googlemaps"> <div class="" style="height: 400px;" id="{{model.alias}}_map"></div> <form ng-submit="lookupAddress('{{model.alias}}')" class="GMapsSearchForm"> <input type="text" class="GMapsAddress" id="{{model.alias}}_GMapsAddress"/> <input class="GMapsAddressSubmitter" type="submit" /> </form> </div>


    Now I have my function in my controller:

    angular.module("umbraco").controller("GMaps.GoogleMapsController",
          function ($rootScope, $scope, notificationsService, dialogService, assetsService)      { 
           ...
             $scope.lookupAddress = function (modelId) {
                 console.log(modelId);
             ...               
             }
    });

    Any help would be very appreciated :)

    -Kim

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Oct 08, 2014 @ 08:08
    Dave Woestenborghs
    1

    Hi Kim,

    I just tested this and this should work.

    What results do you get when you add an alert with the value in your controlller.

    alert($scope.model.alias);

    Dave

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Oct 08, 2014 @ 14:02
    Warren Buckley
    1

    Hi Kim, Like Dave as suggested this value should be working for you.

    You could do this in your controller like so:

     //Property Alias
     var propAlias = $scope.model.alias;
     $scope.uniqueID = propAlias + "_GMapsAddress";
    

    And then in your view it could be like so:

    <input type="text" class="GMapsAddress" id="{{uniqueID}}"/>
    

    But to help with debugging I found this useful to use console.log console.log("Model Value", $scope.model.value); to push stuff to the browser console for debugging alot, or to keep an eye on the main model object I have a textarea like so in my editor/view.

    <textarea>
    {{ model.value | json }}
    </textarea>
    
    <textarea>
    {{ model | json }}
    </textarea>
    

    I hope this helps
    Warren

  • Kim Nedergaard 37 posts 144 karma points
    Oct 08, 2014 @ 14:28
    Kim Nedergaard
    0

    When I finaly got the cached cleared - my problem was solved.

    But thanks a million for your reponses.

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Oct 08, 2014 @ 14:31
    Dave Woestenborghs
    0

    I have my cache disabled in the chrome developer tools. Saves a lot of time refreshing it.

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft