Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Передача переменной из скрипты в html (https://javascript.ru/forum/misc/65728-peredacha-peremennojj-iz-skripty-v-html.html)

triest 05.11.2016 01:46

Передача переменной из скрипты в html
 
Есть javascript с переменными, и есть страниуа.
Как передать переменную на страницу?
В текущем виде ничего не отображаться.
var app = angular.module('jsbin', []);
app.controller('DemoCtrl', function($http) {
    var vm = this;
   var temp1=[];
  
  var URL = 'http://api.openweathermap.org/data/2.5/forecast/daily';
  
  var request = {
    method: 'GET',
    url: URL,
    params: {
       q: 'KansasCity',
      mode: 'json',
      units: 'imperial',
      cnt: '7',
      appid: '3ac1f68b653ffbf72a5f782420062771'
    }
  };
    $http(request)
    .then(function(response) {
   vm.data = response.data;
      temp1[0]= angular.fromJson(response.data); 
       console.log(temp1[0]); 
     console.log(temp1[0].city.name); 
     console.log(temp1[0].city.country);
  
     console.log(temp1[0].list[0].temp.day);
       }).
    catch(function(response) {
      vm.data = response.data;
    });
//  console.log(temp);
});

И есть страница:
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Angular JS</title>
</head>
<body ng-app="jsbin">
  <div ng-controller="DemoCtrl as vm">
  <script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular.js"></script>    
     <h1><b>{{temp1[0].city.name}}</b></h1>
  </div>
 </body>
</html>

destus 05.11.2016 07:26

triest,
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Angular JS</title>
</head>
<body ng-app="jsbin">
  <div ng-controller="DemoCtrl as vm">
  <script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular.js"></script>    
     <h1><b>{{vm.data.city.name}}</b></h1>
  </div>
  <script>
  app = angular
	.module('jsbin', [])
	.controller('DemoCtrl', function($http) {
		var vm = this;
  
		var URL = 'http://api.openweathermap.org/data/2.5/forecast/daily';
  
	    var request = {
			method: 'GET',
			url: URL,
			params: {
			   q: 'KansasCity',
			  mode: 'json',
			  units: 'imperial',
			  cnt: '7',
			  appid: '3ac1f68b653ffbf72a5f782420062771'
			}
		};
		$http(request)
		.then(function(response) {
			vm.data = response.data;
		}).
		catch(function(response) {
			vm.data = response.data;
		});
	});
  </script>
 </body>
</html>


Часовой пояс GMT +3, время: 18:17.