【问题标题】:Add text parameters in angular ui-sref在 angular ui-sref 中添加文本参数
【发布时间】:2015-06-18 21:34:01
【问题描述】:

我正在尝试向 ui-sref 添加参数。如果我尝试这个,它会完美地工作

<a ui-sref="services.test({ id: 2 , other_id: 3 })">test</a>

但是如果我尝试这个它不起作用

<a ui-sref="services.test({ id: firstexmple , other_id: secondone })">test</a>

【问题讨论】:

  • firstexmplesecondone 是变量名吗?或者它们是否打算作为文字值“firstexample”和“secondone”?
  • 文字值,但它不适用于 ""

标签: angularjs angular-ui-router ui-sref


【解决方案1】:

如果您尝试将id 设置为文字值“firstexample”,将other_id 设置为“secondone”,您需要像在纯 JavaScript 代码中编写字符串一样编写它们,所以:

<a ui-sref="services.test({ id: 'firstexmple' , other_id: 'secondone' })">test</a>

(请注意,您不能使用双引号(例如 id: "firstexmple"),因为您已经在使用它们来包装整个 ui-sref 属性的值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-18
    • 1970-01-01
    • 2017-11-19
    • 1970-01-01
    • 1970-01-01
    • 2016-06-07
    • 2015-01-02
    • 1970-01-01
    相关资源
    最近更新 更多