Angular 4: Building a Simple Service

Create the project with angular-cli $ ng new angular-service-project Create a service with angular-cli The service was created with, $ ng g s example-service where ‘g’ is a shortcut for ‘generate’ and ‘s’ is a shortcut for ‘service’. The actual service is at: example-service-service.ts import { Injectable } from ‘@angular/core’; @Injectable() export class ExampleServiceService {…Read More

Angular Service Example

The following code demonstrates how a service can be created in AngularJS. index.html <html> <head> <script src=””></script> <script src=””></script> <script src=””></script> <script src=””></script> <script src=”app.js”></script> <script src=”anotherModule.js”></script> </head> <body> <div ng-app=”mainModule” ng-controller=”mainController as alias”> <b>Invoice:</b> <p>The input is: {{alias.quantity}}</p> <div> Quantity: <input type=”number” min=”0″ ng-model=”alias.quantity”required> </div> <div><p>Add 4 and double it!</p></div> <div> <b>Result:</b> <span>{{}}</span> <button…Read More