Js

$http .jsonp('https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://www.nbrb.by/RSS/?p=RatesDaily&callback=JSON_CALLBACK') .then(function(data, status, headers, config) { $scope.ByBankFeed = data.data.responseData.feed.entries[0].contentSnippet; }); 

HTML

 {{ByBankFeed}} 

Get

 Евро 23 002,00 Доллар США 20 206,00 Российский рубль 294,21 

How can I get the US course, namely 20206 , given that the numbers in this line will change, and the words will be static. Further, the result is planned to apply for the formula.

    2 answers 2

    If you are sure that the format of the string does not change, you can parse with regular expressions:

     $http .jsonp('https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://www.nbrb.by/RSS/?p=RatesDaily&callback=JSON_CALLBACK') .then(function(data, status, headers, config) { var str, usd; str = data.data.responseData.feed.entries[0].contentSnippet; usd = str.match(/.+Доллар США (.+) Российский рубль.*/)[1].replace(/[\s,]/g, '') / 100; $log.log(usd); }); 

    (it doesn’t hurt to check the result of str.match in case of an incorrect source string)

    • and how can I transfer the usd values ​​to the controller, just outside the $ http.jsonp function? Because ng-init = "inputInit ($ parent. $ index, $ index, $ parent. $ last, datafields.cost * ByBankUSD)" does not see $ scope.ByBankUSD - sashatexb

    Of course, this is not the best way - to parse lines to get a number, which would then use it in a formula.

    But if necessary, you can use regular expressions :

    Example.

     var a = "Евро 23 002,00 Доллар США 20 206,00 Российский рубль 294,21"; var r = /Доллар США ([0-9 ]*(,[0-9])*)/i; var res = a.match(r); console.log(res[1]); 

    Update

    If you want to get a list of US exchange rates for different currencies, it is better to use ready-made API than to parse a line.

    For example: