Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
506 views
in Technique[技术] by (71.8m points)

javascript - angular when to use curly brackets

In angular sometimes i have seen curly brackets but some times not.i search a lot but i couldn't find correct question

with curly bracket

ng-src="{{imageSrc}}

without curly bracket

ng-hide="imageSrc"

what i'm asking is why we cannot write ng-hide as

ng-hide="{{imageSrc}} // doesn't work anyway

why there is 2 different syntax for src and hide?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Beacuse they mean two different things. When you use this:

<span data-ng-bind="test">

This means that angular will go to the scope and get value from there with test as key. So value will be $scope.test. But attribte value will be "test"

When you use

ng-src="{{imageSrc}}

then value will be evaluated and placed to the attribute. So value willbe $scope.imageSrc and attribute value will be $scope.imageSrc.

But. Not all tags can wait for evaluation. They think that value {{}} is correct and will not be changed. This cause to bad request. To fix this problem ng-src was created.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...