<div ng-controller="controller">{{text}}</div>
myApp.controller('controller',
function controller($scope, myService) {
myService.Start();
$scope.$watch(function() {
return myService.getText();
}, function(intr) {
if (undefined !== intr) {
$scope.text = intr.text;
}
});
myApp.service('myService', function($http, $interval) {
var text="";
var Start;
var getText;
var Load;
//////////////////
Start = function() {
$interval(Load(), 5000);
};
Load = function() {
$http({method: "GET", url: 'http://example.com/gettext'}).
success(function(data, status, headers, config) {
text = data;
}).error(function(data, status, header, config) {
console.log(status);
});
};
getText=function(){
return text;
};
return{
Start:Start,
getText:getText
};
});