Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I am making an application. I have a form where the user can type in a product. I get the price with an angularjs service. I inject it in. RateInfoService.

So if I type in "Milk" it will say in the DOM {{rate}} -> $2

But if I fill in chips, it will change offcourse to {{rate}} -> $1.50

But what I want to fill in Milk and after that Chips. So I want it to show in the html page

Milk->$2 & Chips->$1.50.

So it will show both items, the user can keep typing in products and submitting it. (ng-click). I might be able to do that in an array but note that I have a refresh rate. Not sure if that's possible to do with an ng-repeat or even if that is possible.

.controller("MainCtrl", function($scope, $http, $timeout, $ionicPlatform, $cordovaLocalNotification, $ionicPopup, RateInfoService, AlarmService, MonitorService) {
      $scope.refreshRate = 5000;

      $scope.refreshData = function() { 
        RateInfoService.getMarket($scope.alarmingMarket).success(function(data) {
          $scope.rate = data.query.results.rate.Rate;
          $scope.updateTime = data.query.results.rate.Time;
        })
  }



<label class="item item-input">
 <span class="input-label">Product name</span>
 <input type="text" min="3" ng-model="hard" name="text" autofocus required>
</label>

Also some extra info

  $scope.submit = function() { 
  $scope.alarmingMarket = $scope.hard
  console.log($scope.monitors);
};

$scope.alarmingMarket = $scope.hard

I used this so it would only get the market price after the user has filled in & pressed submit.

RateInfoService to get the price: http://pastebin.com/gHfhzMjR

I just found out it's possible to dump multiple objects in the url.

https://query.private%20in%20("Milk","Chips")&format;=json&diagnostics;=true&env;=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback;=

How can I do this the best way in angular? i'm new in angularjs (3 weeks)

this is the Json formatted view (Explains the $scope.rate = data.query.results.rate.Rate;)

  "results": {
   "rate": [
    {
     "id": "MILK",
     "Name": "MILK",
     "Rate": "1.1054",
     "Date": "10/26/2015",
     "Time": "9:37pm",
     "Ask": "1.1056",
     "Bid": "1.1052"
    },
    {
     "id": "CHIPS",
     "Name": "CHIPS",
     "Rate": "1.5349",
     "Date": "10/26/2015",
     "Time": "9:37pm",
     "Ask": "1.5352",
     "Bid": "1.5346"

I hope this was enough info. *** Not sure why the styling goes wrong. Sorry for the messy page. Stack overflow gives a good preview of this post, but something goes wrong when I publish it. A lot of the code isn't greyed out

share|improve this question
    
its not clear at all how the code you posted has any relation to the example you provided. – Claies yesterday
    
Is your question is it possible? Because the answer is then. yes, yes it is – cjds yesterday
    
I did an edit. There's now more info about the code – Romano yesterday

1 Answer 1

Sorry don't have enough rep to post a comment. Please give me a plus if this helps so I can get more rep.

From what you posted it seems like you are trying to repeat over items selected by the user and then getting each new rate per item (not sure if $scope.alarmingMarket is an array of items or not).

If you wanted to get all the latest rates for items selected by the user, you have to pass the entire array of items up and get back an array and let the ng-repeat do the work by assigning the value to the $scope.alarmingMarket (if that was your item list).

share|improve this answer
    
I updated the my question with more code info. $scope.alarmingMarket = $scope.hard Basically what the user fills in – Romano yesterday
    
How are you keeping multiple items? $scope.hard looks like it is just a string. If that is the case your code will only work for the last item the user typed in. – 9ers Rule yesterday
    
Yes it's a string. I can't just make an array of it because I can't ram in an array in that return $httpget because in that url, I can only ask for 1 item in that url. – Romano yesterday
    
In that case, in your $scope.refresh() loop through the list of items. But that will cause problems if your list gets too long. – 9ers Rule yesterday
    
Well now you can just change your call to fetch what the user typed in then use the objected returned and just display what you want in an ng-repeat. – 9ers Rule yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.