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);
        }
    });
9
  • 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 Commented May 23, 2016 at 13:17
  • This question should have the answer of dynamically setting the URL of a link. You evidently have getting the routeParam properties down. Commented May 23, 2016 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 Commented May 23, 2016 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. Commented May 23, 2016 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? Commented May 23, 2016 at 13:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.