为什么AngularJS在尝试使用字符串时抱怨表达式中的意外令牌? [英] Why is AngularJS complaining about an unexpected token in an expression when I try to use a string?

查看:199
本文介绍了为什么AngularJS在尝试使用字符串时抱怨表达式中的意外令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div的folowing属性: ng-show =state.name ==='index'。我也尝试过 ng-show ='state.name ===index,但是我收到以下错误:

I have the folowing attribute on a div: ng-show="state.name === 'index'". I've also tried ng-show='state.name === "index", but I keep getting the following error:


语法错误:令牌index'是表达式 [state.name ===index] 从 [index]开始

为什么?

推荐答案

我发现问题。而不是state.name ==='index',我应该写了state.name =='index'。 pkoziowski.opensource是正确的,因为您不能使用条件语句,但是它们的意思是,您不能使用if语句或任何控制流程语句,因此您无法执行此操作:

I found the problem. Instead of "state.name==='index'", I should have written "state.name=='index'". pkoziowski.opensource was right, in that you can't use conditional statements, but what they mean by that, is that you can't use if statements, or any control flow statements for that matter, so you couldn't do this:

<span ng-init="if(state.name == 'o'){doFoo();}">o</span>

这篇关于为什么AngularJS在尝试使用字符串时抱怨表达式中的意外令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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