The restrict option in angular directive, is used to specify how a directive will be invoked in your angular app i.e. as an attribute, class, element or comment.
There are four valid options for restrict:
'A' (Attribute)- <span my-directive></span>
'C' (Class)- <span class="my-directive:expression;"></span> 'E' (Element)- <my-directive></my-directive>
'M' (Comment)- <!-- directive: my-directive expression -->
Monday, December 30, 2019
What are the new features introduced in Angular 5?
Angular 5 came with a lot of new features which help and
attract developer at any point of time on Angular specific task. It also has
some earlier bug fixing which also helps angular developer for smooth coding.
AOT feature is making as a default feature.
- 1. Activating watching mode which helps developer especially in debug.
- 2. Introducing type checking utility for the template.
- 3. Metadata saving and fetching utility making more advance which makes it more flexible.
- 4. Unwanted ts file like *.ngfactory.ts has been removed permanently.
- 5. Displaying error message are more meaningful which help angular developer on error investigation.
- 6. Feature upgrades are more smooth then earlier.
- 7. Introducing new Tree shakeable components help angular developer for a new feature.
- 8. More advance in case of Hybrid upgrade application.
- 9. Improve their performance more than earlier versions.
What are the key
components of Angular?
Angular has the below key components,
- 1. Component: These are the basic building blocks of angular application to control HTML views.
- 2. Modules: An angular module is set of angular basic building blocks like component, directives, services etc. An application is divided into logical pieces and each piece of code is called as "module" which perform a single task.
- 3. Templates: This represent the views of an Angular application.
- 4. Services: It is used to create components which can be shared across the entire application.
- 5. Metadata: This can be used to add more data to an Angular class.
Thursday, September 7, 2017
What are different ways to invoke a directive?
There are four methods to invoke a directive in your angular app which are equivalent.
|
Method
|
Syntax
|
|
|
|
|
As an attribute
|
<span my-directive></span>
|
|
|
|
|
As a class
|
<span class="my-directive:
expression;"></span>
|
|
|
|
|
As an element
|
<my-directive></my-directive>
|
|
|
|
|
As a comment
|
<!-- directive: my-directive
expression -->
|
|
|
|
How to create custom directives in AngularJS?
You can create your own custom directive by using following syntax:
var app = angular.module('app', []);
//creating custom directive syntax
app.directive("myDir", function () {
return {
restrict: "E", //define directive type like E = element, A = attribute, C = class, M = comment
scope: { //create a new child scope or an isolate scope
title: '@' //@ reads the attribute value,
//= provides two-way binding,
//& works with functions
},
template: "<div>{{ myName }}</div>",// define HTML markup
templateUrl: 'mytemplate.html', //path to the template, used by the directive
replace: true | false, // replace original markup with template yes/no
transclude: true | false, // copy original HTML content yes/no
controller: function (scope) { //define controller, associated with the directive template
//TODO:
},
link: function (scope, element, attrs, controller) {//define function, used for DOM manipulation
//TODO:
}
}
});
var app = angular.module('app', []);
//creating custom directive syntax
app.directive("myDir", function () {
return {
restrict: "E", //define directive type like E = element, A = attribute, C = class, M = comment
scope: { //create a new child scope or an isolate scope
title: '@' //@ reads the attribute value,
//= provides two-way binding,
//& works with functions
},
template: "<div>{{ myName }}</div>",// define HTML markup
templateUrl: 'mytemplate.html', //path to the template, used by the directive
replace: true | false, // replace original markup with template yes/no
transclude: true | false, // copy original HTML content yes/no
controller: function (scope) { //define controller, associated with the directive template
//TODO:
},
link: function (scope, element, attrs, controller) {//define function, used for DOM manipulation
//TODO:
}
}
});
What is the role of ng-app, ng-init and ng-model directives?
The main role of these directives is explained as:
• ng-app - Initialize the angular app.
• ng-init - Initialize the angular app data.
• ng-model - Bind the html elements like input, select, text area to angular app model.
• ng-app - Initialize the angular app.
• ng-init - Initialize the angular app data.
• ng-model - Bind the html elements like input, select, text area to angular app model.
What are Directives in AngularJS?
AngularJS directives are a combination of AngularJS template markups (HTML attributes or elements, or CSS classes) and supporting JavaScript code. The JavaScript directive code defines the template data and behaviors of the HTML elements.
AngularJS directives are used to extend the HTML vocabulary i.e. they decorate html elements with new behaviors and help to manipulate html elements attributes in interesting way.
There are some built-in directives provided by AngularJS like as ng-app, ng-controller, ng-repeat, ng-model etc.
AngularJS directives are used to extend the HTML vocabulary i.e. they decorate html elements with new behaviors and help to manipulate html elements attributes in interesting way.
There are some built-in directives provided by AngularJS like as ng-app, ng-controller, ng-repeat, ng-model etc.
How AngularJS expressions are different from the JavaScript expressions?
AngularJS expressions are much like JavaScript expressions but they are different from JavaScript expressions in the following ways:
1. Angular expressions can be added inside the HTML templates.
2. Angular expressions doesn't support control flow statements (conditionals, loops, or exceptions).
3. Angular expressions support filters to format data before displaying it.
1. Angular expressions can be added inside the HTML templates.
2. Angular expressions doesn't support control flow statements (conditionals, loops, or exceptions).
3. Angular expressions support filters to format data before displaying it.
What are Expressions in AngularJS?
AngularJS expressions are much like JavaScript expressions, placed inside HTML templates by using double braces such as: {{expression}}. AngularJS evaluates expressions and then dynamically adds the result to a web page. Like JavaScript expressions, they can contain literals, operators, and variables.
There are some valid AngularJS expressions:
• {{ 1 + 2 }}
• {{ x + y }}
• {{ x == y }}
• {{ x = 2 }}
• {{ user.Id }}
There are some valid AngularJS expressions:
• {{ 1 + 2 }}
• {{ x + y }}
• {{ x == y }}
• {{ x = 2 }}
• {{ user.Id }}
What are Filters in AngularJS?
Filters are used to format data before displaying it to the user. They can be used in view templates, controllers, services and directives. There are some built-in filters provided by AngularJS like as Currency, Date, Number, OrderBy, Lowercase, Uppercase etc. You can also create your own filters.
Filter Syntax
{{ expression | filter}}
Filter Example
<script type="text/javascript">
{ { 14 | currency } } //returns $14.00 </script>
Filter Syntax
{{ expression | filter}}
Filter Example
<script type="text/javascript">
{ { 14 | currency } } //returns $14.00 </script>
What is Angular Prefixes $ and $$?
To prevent accidental name collisions with your code, Angular prefixes names of public objects with $ and names of private objects with $$. So, do not use the $ or $$ prefix in your code.
Wednesday, September 6, 2017
What is Global API?
Global API provides you global functions to perform common JavaScript tasks such as comparing objects, deep copying, iterating through objects, and converting JSON data etc. All global functions can be accessed by using the angular object. The list of global functions is given below:
|
Name
|
Description
|
|
|
Converts the specified
string to lowercase.
|
||
|
|
|
|
|
Converts the specified
string to uppercase.
|
||
|
|
|
|
|
Invokes the iterator
function once for each item in obj collection, which can be
|
||
|
either an object or an array.
|
||
|
|
||
|
|
|
|
|
Determines if a reference
is undefined.
|
||
|
|
|
|
|
Determines if a reference
is defined.
|
||
|
|
|
|
|
Determines if a reference
is an Object.
|
||
|
|
|
When dependent modules of a module are loaded?
A module might have dependencies on other modules. The dependent modules are loaded by angular before the requiring module is loaded.
In other words the configuration blocks of the dependent modules execute before the configuration blocks of the requiring module. The same is true for the run blocks. Each module can only be loaded once, even if multiple other modules require it.
In other words the configuration blocks of the dependent modules execute before the configuration blocks of the requiring module. The same is true for the run blocks. Each module can only be loaded once, even if multiple other modules require it.
What is difference between config() and run() method in AngularJS?
Configuration block – This block is executed during the provider registration and configuration phase. Only providers and constants can be injected into configuration blocks. This block is used to inject module wise configuration settings to prevent accidental instantiation of services before they have been fully configured. This block is created using config() method.
angular.module('myModule', []).
config(function (injectables) { // provider-injector
// This is an example of config block.
// You can have as many of these as you want.
// You can only inject Providers (not instances)
// into config blocks.
}).
run(function (injectables) { // instance-injector
// This is an example of a run block.
// You can have as many of these as you want.
// You can only inject instances (not Providers)
// into run blocks
});
Run block – This block is executed after the configuration block. It is used to inject instances and constants. This block is created using run() method. This method is like as main method in C or C++.
The run block is a great place to put event handlers that need to be executed at the root level for the application.
For example, authentication handlers.
angular.module('myModule', []).
config(function (injectables) { // provider-injector
// This is an example of config block.
// You can have as many of these as you want.
// You can only inject Providers (not instances)
// into config blocks.
}).
run(function (injectables) { // instance-injector
// This is an example of a run block.
// You can have as many of these as you want.
// You can only inject instances (not Providers)
// into run blocks
});
Run block – This block is executed after the configuration block. It is used to inject instances and constants. This block is created using run() method. This method is like as main method in C or C++.
The run block is a great place to put event handlers that need to be executed at the root level for the application.
For example, authentication handlers.
How angular modules load the dependencies?
An angular module use configuration and run blocks to inject dependencies (like providers, services and constants) which get applied to the angular app during the bootstrap process.
What is core module in AngularJS?
ng is the core module in angular. This module is loaded by default when an angular app is started. This module provides the essential components for your angular app like directives, services/factories, filters, global APIs and testing components.
What components can be defined within AngularJS modules?
You can define following components with in your angular module:
1. Directive
2. Filter
3. Controller
4. Factory
5. Service
6. Provider
7. Value
8. Config settings and Routes
1. Directive
2. Filter
3. Controller
4. Factory
5. Service
6. Provider
7. Value
8. Config settings and Routes
What are Modules in AngularJS?
AngularJS modules are containers just like namespace in C#. They divide an angular app into small, reusable and functional components which can be integrated with other angular app. Each module is identified by a unique name and can be dependent on other modules. In AngularJS, every web page (view) can have a single module assigned to it via ng-app directive.
Creating an AngularJS module
<script type="text/javascript">
// defining module angular.module('myApp', []);
//OR defining module which has dependency on other modules angular.module('myApp', ['dependentModule1', 'dependentModule2']);
</script>
Creating an AngularJS module
<script type="text/javascript">
// defining module angular.module('myApp', []);
//OR defining module which has dependency on other modules angular.module('myApp', ['dependentModule1', 'dependentModule2']);
</script>
Using an AngularJS module into your app
You can bootstrap your app by using your AngularJS module as given below:
<html ng-app="myApp">
<head>
...
</head>
<body>
...
</body>
How AngularJS handle the security?
AngularJS provide following built-in protection from basic security holes:
1. Prevent HTML injection attacks.
2. Prevent Cross-Site-Scripting (CSS) attacks.
3. Prevent XSRF protection for server side communication.
Also, AngularJS is designed to be compatible with other security measures like Content Security Policy (CSP), HTTPS (SSL/TLS) and server-side authentication and authorization that greatly reduce the possible attacks.
1. Prevent HTML injection attacks.
2. Prevent Cross-Site-Scripting (CSS) attacks.
3. Prevent XSRF protection for server side communication.
Also, AngularJS is designed to be compatible with other security measures like Content Security Policy (CSP), HTTPS (SSL/TLS) and server-side authentication and authorization that greatly reduce the possible attacks.
What are AngularJS features?
The features of AngularJS are listed below:
1. Modules
2. Directives
3. Templates
4. Scope
5. Expressions
6. Data Binding
7. MVC (Model, View & Controller)
8. Validations
9. Filters
10. Services
11. Routing
12. Dependency Injection
13. Testing
1. Modules
2. Directives
3. Templates
4. Scope
5. Expressions
6. Data Binding
7. MVC (Model, View & Controller)
8. Validations
9. Filters
10. Services
11. Routing
12. Dependency Injection
13. Testing
Subscribe to:
Posts (Atom)
What is restrict option in directive?
The restrict option in angular directive, is used to specify how a directive will be invoked in your angular app i.e. as an attribute, class...
-
<script type="text/javascript"> var days = new Array(); days[0] = "Sunday" days[1] = "Monday"...
-
Objects have "prototypes" from which they may inherit fields and functions. <script type="text/javascript">...