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
236 views
in Technique[技术] by (71.8m points)

angularjs - Is there any directive called ng-int? What is wrong with my ng-init syntax?

I want to initialize an angular variable with local scope BWCount.

When i use ng-init I get the following error Error: $parse:syntax

But when I use ng-int (It was a typo, but turns out to be a surprising serendipity), it works fine and I can even use that variable in other markups.

What is happening here? Am I using the incorrect syntax for ng-init? And what is this ng-int (I don't have any custom directive called ngInt)

I am using Visual studio 2013 and have have the following markup:

<div ng-int="{{BWCount=(oCurrentDepartment.oMachineAccount|sumByKey:'BWCOUNT')}}">{{BWCount}}</div>

Notice ng-int

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

ng-init expects an angular expression, so you must not have {{ }} around it.

Your code works simply because angular considers ng-int as a basic HTML attribute, and evaluates the expression surrounded by {{ }} at each digest cycle. Not just at initialization.

ng-init should be avoided anyway. That code should be in your controller.


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

...