0

Within my HTML view file I have a link that looks like this:

url: 'http://localhost:3000/readings?limit=100&nodeID=0001'

This is part of an Ajax call that gets readings from my local database for nodeID = 0001.

In the corresponding .js controller file I have the following function:

.controller('ReadingsViewCtrl', function ($scope, $routeParams) 

  {

     $scope.model = {
        message: $routeParams.id}


  });

I can now address the ID as {{model.message}} within my HTML view file.

What I want to do is somehow embed the {{model.message}} into the URL above so that I can get readings for arbitrary nodes, i.e. have something like url: 'http://localhost:3000/readings?limit=100&nodeID={{model.message}}'

This way I can get readings for an arbitrary nodeID passed in as a parameter instead of just node 0001. How can I do this?

EDIT: As asked here is the rest of the function that contains the URL property, it is part of an Ajax call that gets data from my database.

$.ajax({

        url: 'http://localhost:3000/readings?limit=100&nodeID=0001',
        dataType: 'json',
        type: 'get',
        cache: true, 
        success: function(data){
            var jsonobject = [];

            $(data).each(function(index, value){

                var list = [];
                var m = moment(value.time, 'YYYY-MM-DDTHH:mm:ss.SSSZZ');
                var ts = moment(value.time).valueOf();
                console.log(ts);
                list[0] = ts;
                list[1] = value.litres;
                jsonobject.push(list);

            })

             $('#container').highcharts('StockChart', {


            rangeSelector : {
                selected : 1
            },

            title : {
                text : 'Water consumption in Litres/sec'
            },

            series : [{
                name : 'Litres per flush',
                data : jsonobject,
                tooltip: {
                    valueDecimals: 2
                }
            }]
        });

            console.log(jsonobject);
        }
    });
Django
  • 343
  • 1
  • 4
  • 23
  • What is `url` property a member of? Not enough context shown. Are you trying to get a dynamically generated template from server or trying to get data based on `message`? Not really clear what you are asking – charlietfl May 23 '16 at 13:17
  • [This question](http://stackoverflow.com/questions/24349731/dynamically-set-the-value-of-ui-sref-angularjs) should have the answer of dynamically setting the URL of a link. You evidently have getting the routeParam properties down. – Harris May 23 '16 at 13:20
  • @charlietfl Thanks for your reply, I've added the full function, I'm trying to query my REST API using the nodeID that will be passed as a parameter – Django May 23 '16 at 13:27
  • @Django FYI, it's considered a _really_ bad practice to use jQuery in an Angular application, and basically everything you're doing has an Angular implementation. – Harris May 23 '16 at 13:40
  • @HarrisWeinstein Thanks, I'm a beginner, this is a prototype, I'd like to get minimum functionality working and then I can change things around, any idea on how to solve my problem? – Django May 23 '16 at 13:45
  • @Django The easiest thing is to just look up "Angular ". The official documentation is the first place you can check out (such as for [HTTP requests](https://docs.angularjs.org/api/ng/service/$http) or [Highcharts](http://www.highcharts.com/blog/194-using-highcharts-with-angular-js)), but if you need more help, most any problem you have at this point has already been asked on SO. I'd recommend not using jQuery for even prototyping; Angular really will be faster and easier. Also, see my first comment, which has a reference to an answered question that solves this. – Harris May 23 '16 at 13:55
  • you don't need anything special...just concatenate the variable with the url string and as mentioned you should be using angular `$http` instead of jQuery – charlietfl May 23 '16 at 15:30
  • @charlietfl Would you mind posting a solution with concatenation? I am new to JS – Django May 23 '16 at 15:53
  • Do a web search for string concatenation. This is extremely trivial – charlietfl May 23 '16 at 16:04

0 Answers0