Execute
<!DOCTYPE html> <html> <head> <title>Wikitechy AngularJS tutorial</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script> </head> <body> <div ng-app="myApp" ng-controller="providerCtrl"> <h3>provider example in AngularJS Tutorial</h3> Display the name using provider: <b>{{ providervalue }}</b> </div> <script> var app = angular.module('myApp',[]); app.provider('unicorn', function() { this.setName = function(name) { this.name = name; }; this.$get = function() { var self = this; return { getvalue: function() { return self.name + "!!!"; } }; }; }); app.config(function(unicornProvider){ unicornProvider.setName('welcome to AngularJS Tutorial'); }); app.controller('providerCtrl', function($scope,unicorn) { $scope.providervalue = unicorn.getvalue(); }); </script> </body> </html>
www.wikitechy.com © Copyright 2016. All Rights Reserved.