<p ng-controller="listCtrl">
<h1>这是列表页面</h1>
<ul>
<li ng-repeat="item in myList"><a href="#/myDetail/{{$index}}">{{item}}</a></li>
<li ng-repeat="item in myList"><button ng-click="jump('/myDetail/'+$index)">{{item}}</button></li>
</ul>
</p>
As the title says, in the above code, I need to get the $index value as a parameter. I need to add {{}} to the first li to get the value, but there is no need to add it to the second li; how should I do this? distinguish? ?
In order to parse data in native HTML, you need to use {{}} to bind data, but there is no need for this behind the ng command.
{{ $var }}
wrapped template variable , used when directly output the variable value without additional parsing (such as filter processing, as an instruction parameter, as a function parameter), otherwise,ng -click="jump('/myDetail/'+ $index)"
is the parameter called in the command.The simple criterion is
If the type assigned to the current attribute is a literal type, such as an attribute in an html template, or an attribute with
@
as a modifier in a directive, then if you do not add double curly brackets when assigning the value, it will be a literal value. To calculate, if you want to parse it as a variable, you need to add double curly braces.If the type assigned to the current attribute is a non-string type, such as various built-in instructions in the angular template, or attributes modified with
<
,=
,&
in the instructions, then the assignment will be as follows The syntax rules of js are parsed. In this case, there is no need to add curly brackets.First explain the two types in Angular:
Then you can refer to the context to determine whether you are writing a JS-like part or writing a string literal, so that it is easy to judge whether you need a template or an expression.