Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When and why to use &?, =?, @? in AngularJS?

I followed some tutorials to create angular directives. In the isolate scope, some tutorials define scope like this:

scope: {
  model: '=?',
  data:  '@?' 
}

Meanwhile, some tutorials define scope without question mark like this:

scope: {
  model: '=',
  data:  '@'
}

Can anybody explain me the difference or the purpose of these with examples? Thank you.

like image 662
Shaohao Avatar asked Jul 23 '15 13:07

Shaohao


People also ask

When and why should is used?

Should is used to say that something is the proper or best thing to do, or to say that someone ought to do something or must do something. Adam could visit us on Monday. This tells us that it is possible Adam will visit on Monday, maybe he can visit us, but maybe he has other options, too.

What is the use of when?

We use when to mean '(at) the time that'. We use since to refer to a particular time in the past until another time or until now: I had a great time when I went to the coast.

How do you use when in a sentence?

It was a time when people didn't have to lock their doors. the happy days when we were together We're still waiting for the test results, when we'll decide our next move. Conjunction When he finally showed up, he was drunk. When I was in school, we didn't have computers.

When to Use That is why in a sentence?

That in that is why is usually the subject of a sentence or a clause that can stand alone: I want to be involved in town government, and that is why I'm running for mayor. My mother always gives me good advice, so that is why I need to ask her opinion.


1 Answers

The &, @, and = symbols are used to define the bindings (one-way, bi-directional, etc) for isolated scope objects, as you already know. Here is a pretty thorough tutorial on how all this works.

The ? symbol is used to indicate that the parent scope property to which the isolated scope binding refers to is optional. This means that if for some reason the parent scope property doesn't exist, then your application will continue to run without throwing the NON_ASSIGNABLE_MODEL_EXPRESSION exception.

like image 135
Daniel Cottone Avatar answered Oct 03 '22 07:10

Daniel Cottone