Differencebetween & VS @ and = in Angularjs

What is the difference between & vs @ and = in angularJS

@ allows a value defined on the directive attribute to be passed to the directive's isolate scope. The value could be a simple string value (myattr="hello") or it could be an AngularJS interpolated string with embedded expressions (myattr="my_{{helloText}}"). Think of it as "one-way" communication from the parent scope into the child directive. John Lindquist has a series of short screencasts explaining each of these. Screencast on @ is here: https://egghead.io/lessons/angularjs-isolate-scope-attribute-binding

& allows the directive's isolate scope to pass values into the parent scope for evaluation in the expression defined in the attribute. Note that the directive attribute is implicitly an expression and does not use double curly brace expression syntax. This one is tougher to explain in text. Screencast on & is here: https://egghead.io/lessons/angularjs-isolate-scope-expression-binding

= sets up a two-way binding expression between the directive's isolate scope and the parent scope. Changes in the child scope are propagated to the parent and vice-versa. Think of = as a combination of @ and &. Screencast on = is here: https://egghead.io/lessons/angularjs-isolate-scope-two-way-binding

And finally here is a screencast that shows all three used together in a single view: https://egghead.io/lessons/angularjs-isolate-scope-review

Difference between Angularjs and angular

AngularJS is the first version of Angular.

AngularCLI is a tool used to generate angular components, They are not comparable.

What you might mean, is what is the difference between Angular and AngularJS.

The answer to this question is that AngularJS is the first version of Angular.

It works with javascript and it is still getting supported but it is not compatible with Angular.

I'd suggest you start with Angular (Can also be called Angular2 or Angular4).

It is very confusing, but to sum it up, AngularJS is an old version.

Angular is the newer version and since everyone is migrating to Angular.

I would suggest you learn Angular instead of AngularJS.

Difference between constant and value in AngularJS

Constants can put anywhere whereas Values cannot be added anywhere. Also constants cannot be intercepted by decorators whereas values can be intercepted by decorators.

Also refer: Value and Constants

The difference between a value and a constant service is that the
former can only be injected (and thus be used) in a service or a
controller while the latter can also be injected into a module
configuration function.. (I will discuss the module configuration
function in a future post).

Can anyone explain the difference between expression, ng-bind and ng-model?

ng-bind and ng-model both are the inbuilt directives in Angular.

While ng-bind helps you to bind a value to innerHTML of an element, ng-model helps you bind the data to the interactive elements (i.e. <input>, <checkbox>, <textarea>), you got it..

Usage:

ng-bind

If you have
$scope.textFromComponent = "Superman" in your controller.

<span ng-bind="textFromComponent"></span> binds this value within this span element.

{{ }}

The same behaviour can be achieved using {{}}.

These set of curly-brackets are called Interpolation directives and they work as a short-hand to ng-bind. While using them you no more need to write ng-bind rather you directly bind them. Like:

<span>{{textFromComponent}}</span>

ng-model

<input ng-model="textFromComponent" />

binds this value to the value property of your input element. This binds the value two-way which means if you make any changes to $scope.textFromComponent in your code, it will reflect on screen automatically. At the same time, if user makes any change to it ( since they are interactive elements, user can change them) the changed value will be passed to your code.

What is the difference between expect and when in $httpBackend

$httpBackend.expect - specifies a request expectation

$httpBackend.when - specifies a backend definition

From: https://docs.angularjs.org/api/ngMock/service/$httpBackend

Request expectations provide a way to make assertions about requests made by the application and to define responses for those requests. The test will fail if the expected requests are not made or they are made in the wrong order.

Backend definitions allow you to define a fake backend for your application which doesn't assert if a particular request was made or not, it just returns a trained response if a request is made. The test will pass whether or not the request gets made during testing.

Therefore, it means that if you set a request expectation with expect the test will fail if you don't get the exact same request, exact number of times. However if you set it with when, the backend will respond appropriately, but it has no expectations about how many requests (if any) will come therefore will not fail the test.

What is the difference between angularjs and angulardart

The main point you should know, is that there's AngularJS and Angular. Angular was a rewrite of AngularJS that was released in September 2016. Angular is usually written in Typescript, but you can also write it in Dart.

  1. AngularDart is Angular written in Dart
  2. AngularJS is totally different than Angular, and not related to AngularDart
  3. AngularDart website lays out the steps for getting started with it

Difference between the below two controllers

They serve the same function, except the top controller is what you should use if you're going to minify your code. AngularJS uses parameter names to inject the values to your controller function. In JavaScript minification process, these parameters are renamed to shorter strings. By telling which parameters are injected to the function with a string array, AngularJS can still inject the right values when the parameters are renamed.



Related Topics



Leave a reply



Submit