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="factoryCtrl"> <h3>square value using factory method in AngularJS</h3> <p>square value of 50 is <b>{{ result}}</b> </p> </div> <script> var app = angular.module('myApp', []); app.factory('square', function() { var factory= { }; factory.myFunc = function (a) { return a*a; } return factory; }); app.controller('factoryCtrl', function($scope, square) { $scope.result = square.myFunc(50); }); </script> </body> </html>
www.wikitechy.com © Copyright 2016. All Rights Reserved.