I want to make a widget by using angularjs's custom directive, but stuck somewhere injecting $http service in it.
var app = angular.module('app',[]);
app.directive('users',function($scope,$http){
return {
$http.get('https://jsonplaceholder.typicode.com/users')
.then(function(response) {
$scope.user = response.data;
})
}
})
Any thought how can it be done? I know above code doesn't work but I have no clue how to continue.
restrict,template, etc.). Please read the directive tutorial on Angular website. If you need to execute some code when the directive binds, it can be done in thelinkmethod.