难以调试错误 - 第2列的令牌'{'无效密钥 [英] Having a hard time debugging error - Token '{' invalid key at column 2

查看:118
本文介绍了难以调试错误 - 第2列的令牌'{'无效密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个我无法调试的错误。

I have encountered an error which I'm unable to debug.

form-field.html

form-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>

我收到以下错误:

在浏览器中:


错误:[$ 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] 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

在角度站点上:


错误:$ parse:syntax语法错误语法错误:令牌'{'无效键
at表达式[{{field}}。$ error]的第2列,起价为
[{field}}。$ error]。

Error: $parse:syntax Syntax Error Syntax Error: Token '{' invalid key at column 2 of the expression [{{field}}.$error] starting at [{field}}.$error].

有人知道为什么吗?谢谢!

Does someone know why? Thanks!

推荐答案

我注意到在将数据绑定到自定义指令的属性时也会发生此错误。其中

I notice that this error also happens when binding data to an attribute on a custom directive. Where

$scope.myData.value = "Hello!";

这会导致错误:

<my-custom-directive my-attr="{{myData.value}}"></my-custom-directive>

但这样可行:

<my-custom-directive my-attr="myData.value"></my-custom-directive>

这篇关于难以调试错误 - 第2列的令牌'{'无效密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆