Injector ANGULAR JS
Each application is made up of objects which collaborate together to get the things done and these objects need to be instantiated for them to work and for the app to perform. In angular js, most of these objects are instantiated with the help of injector services. The injector services create two types of objects, services and specialized objects.
- Services: These are the injector objects whose services API is defined by the developer writing the service.
- Specialized: These are the objects created for specific Angular Framework API and examples are Controllers, Directives, Filters or animations.
As we said above that injector instantiates objects and create objects but it also needs to know how to create these objects for which recipe is registered. There are five commonly used recipe i,e. Value, Constant, provider, service, factory. The most commonly used service is Provider.
CREATE A MODULE IN ANGULAR JS
angular.module('myapp',[]).controller('controllers',function($scope){ $scope.lastname="Dhiman"; $scope.quantitiy=200; $scope.price=300;
Price of an item is {{quantitiy * price | currency}}
Explain $scope and $rootscope in Angular JS
- scope: This is an instance object of ng-controller on a page and is used to pass a value in expressions in a page. For example
function scopefunction1($scope) { $scope.controllername= "Rita Dhiman"; }If you use {{controllername}}
- $rootScope : This is a parent object of all “$scope” angular objects which area created in a web page. Angular js first encounters any ng-app directive and then creates $rootScope object in memory.
FILTERS IN ANGULAR JS
Filters are used to modify data in Angular JS, few of the commonly used Angular JS filters are:
- uppercase: It converts the text to uppercase
Example:Name converted to Upper Case: {{fullName | uppercase}} - lowecase: It converts the text to lowercase
Example:Name converted to lowerCase: {{fullName | lowercase}} - currency: Puts currency symbol and format the text in a currency format instead of an ordinary text
Example:Price to currency filter: {{price | currency}} - Date: It formats the text in date format
AngularJS supports inbuilt internationalization for only three types of filters, which are Currency, Date, and Numbers.
EXPRESSIONS IN ANGULAR JS
Expressions are used to bind application data with HTML and are quite similar to ng-bind directive of Angular JS. Expressions are written inside double curly bracket such as {{ }}
Depending upon the requirements, expressions could be used as:- Numbers
Example: Expense on Cookies: {{cost * quantity}} Rs - String
Example: Hello {{people.firstname + " " + peopl.lastname}}! - Object
Example: Phone No: {{employee.phoneno}} - Array
Example: Marks(subject): {{subject[7]}}
Hello {{employee.firstname + " " + employee.lastname}}!
Expense on Books : {{cost * quantity}} Rs
Roll No: {{employee.phoneno}}
Employee No: {{emmployeeid[3]}}