我遇到了一個我無法調試的錯誤。難以調試錯誤 - 令牌'{'第2列的無效密鑰
形式,field.html
<div class='row form-group' ng-form="{{field}}" ng-class="{ 'has-error': {{field}}.$dirty && {{field}}.$invalid }">
<label class='col-sm-2 control-label'> {{ field | labelCase }} <span ng-if='required'>*</span></label>
<div class='col-sm-6' ng-switch='required'>
<input ng-switch-when='true' ng-model='record[field][0]' type='{{record[field][1]}}' class='form-control' required ng-change='update()' ng-blur='blurUpdate()' />
<div class='input-group' ng-switch-default>
<input ng-model='record[field][0]' type='{{record[field][1]}}' class='form-control' ng-change='update()' ng-blur='blurUpdate()' />
<span class='input-group-btn'>
<button class='btn btn-default' ng-click='remove(field)'><span class='glyphicon glyphicon-remove-circle'></span></button>
</span>
</div>
</div>
<div class='col-sm-4 has-error' ng-show='{{field}}.$dirty && {{field}}.$invalid' ng-messages='{{field}}.$error'>
<p class='control-label' ng-message='required'> {{ field | labelCase }} is required. </p>
<p class='control-label' ng-repeat='(k, v) in types' ng-message='{{k}}'> {{ field | labelCase }} {{v[1]}}</p>
</div>
</div>
new.html
<h2> New Contact </h2>
<form name='newContact' novalidate class='form-horizontal'>
<form-field record='contact' field='firstName' live='false' required='true'></form-field>
<div class='row form-group'>
<div class='col-sm-offset-2'>
<button class='btn btn-primary' ng-click='save()'> Create Contact </button>
</div>
</div>
</form>
,我發現了以下錯誤:
在瀏覽器:
Error: [$parse:syntax] http://errors.angularjs.org/1.4.1/ $parse/syntax?p0=%7B&p1=invalid%20key&p2=2&p3=%7B%7Bfield%7D%7D.%24error&p4=%7Bfield%7D%7D.%24error
在角點:
Error: $parse:syntax Syntax Error Syntax Error: Token '{' invalid key at column 2 of the expression [{{field}}.$error] starting at [{field}}.$error].
有人知道爲什麼嗎?謝謝!
您需要更新{{場}}到現場每當納克級和NG-表演引用。 – nikhil
Nikhil - 它在這個項目中工作正常:https://github.com/tutsplus/Building-a-Web-App-From-Scratch-With-AngularJS,但不適合我。 – Angelo
ng-show屬性不應該包含{{}}。只需試試'「field。$ dirty」'而不是。 –