Angularjs demonstrates the Service function and angularjsservice
In angularjs, We can customize our own service. It can be said that it is a custom method, a function.
Let's demonstrate it step by step:
First, define an app for angularjs:
Var demoApp = angular. module ('demoapp ', []);Source Code
The demoApp name is the defined app. The focus of this article is to define a service:
DemoApp. service ('calcservice', function () {this. addition = function (num1, num2) {return num1 + num2;} this. substruction = function (num1, num2) {return num1-num2;} this. multiplication = function (num1, num2) {return num1 * num2;} this. division = function (num1, num2) {return num1/num2 ;}});Source Code
Angularjs has another controller:
DemoApp. controller ('democontroller', function ($ scope, calcService) {$ scope. result1 = calcService. addition (12, 4); $ scope. result2 = calcService. substruction (14, 3); $ scope. result3 = calcService. multiplication (7, 9); $ scope. result4 = calcService. division (15, 3 );});Source Code
Finally, implement the ASP. net mvc View:
Result of running the program: