Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
252 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...