Current weather example - scope: {}
by emilcieslar
HTML
<div ng-app="WeatherApp" ng-controller="mainController as main">
<weather-widget weather-data="main.currentWeather"></weather-widget>
</div>
JavaScript
angular.module('WeatherApp', [])
.controller('mainController', ['$scope', function($scope) {
var self = this;
self.currentWeather = {
description: 'Moc hezky',
temperature: 24,
windSpeed: 20
}
}])
.directive('weatherWidget', [function() {
return {
scope: {
weatherData: '='
},
template: '<h2>Aktuální počasí: {{weatherData.description}}</h2>' +
'<p>Je {{weatherData.temperature}} stupňů, s rychlostí větru {{weatherData.windSpeed}} m/s.</p>'
}
}])