In Angularjs, we can customize our own service. It can be said to be a custom method, a function.
Let's take a step-by-step demonstration:
First define an app for Angularjs:
var demoApp = angular.module ('demoApp', []);
Source Code
The DemoApp name is the app we've defined. The following is the focus of this article, defining a service:
Demoapp.service ('Calcservice', function () { This. addition =function (NUM1, num2) {returnNUM1 +num2; } This. Substruction =function (NUM1, num2) {returnNUM1-num2; } This. multiplication =function (NUM1, num2) {returnNUM1 *num2; } This. Division =function (num1,num2) {returnNUM1/num2; }});
Source Code
ANGULARJS also has a controller:
Demoapp.controller ('democontroller', function ($scope, calcservice) { = Calcservice.addition (4); = Calcservice.substruction (3); = Calcservice.multiplication (79); = Calcservice.division (3);});
Source Code
The final implementation of the ASP. NET MVC View:
The results of the program run:
ANGULARJS Demo Service Features