$stateParams将值转换为字符串
$stateParams converting value to string
我正在使用UI-Router
。以下是我通过ui-sref
:路由到的一个状态
.state("community", {
url: "/community/:community_id",
controller: "CommunityCtrl",
templateUrl: "/static/templates/community.html"
})
在我的一个模板中,我去了"社区"状态:
<div ui-sref="community({community_id: community.community_id})"></div>
这是我的社区对象:
{
name: 'Community name',
community_id: 11 //int, not a string
}
正如您所看到的,键"community_id"包含一个int值,而不是字符串值。然而,当我通过$stateParams
访问此参数时,我得到:
community_id: "11" //string
为什么我会被绳子缠住?
将community_id
作为数字(int)的最简单方法是将该参数声明为int
-{community_id:int}
.state("community", {
url: "/community/{community_id:int}",
controller: "CommunityCtrl",
templateUrl: "/static/templates/community.html"
})
检查有关.state()
设置的文档url
:
具有可选参数的
url
片段。当一个状态被导航或转换到时,$stateParams
服务将使用传递的任何参数填充。(有关可接受模式的更多详细信息,请参阅UrlMatcher UrlMatcher})
示例:
url: "/home" url: "/users/:userid" url: "/books/{bookid:[a-zA-Z_-]}" url: "/books/{categoryid:int}" url: "/books/{publishername:string}/{categoryid:int}" url: "/messages?before&after" url: "/messages?{before:date}&{after:date}" url: "/messages/:mailboxid?{before:date}&{after:date}"
相关文章:
- 如何在JavaScript中将字符串转换为函数引用
- 如何在 Javascript 中将变量的值从字符串转换为整数
- 将字符串转换为格式化日期
- IE在将字符串转换为日期时从日期中删除4小时
- node.js将字符串转换为要上传到Web服务器的文件
- 将字符串转换为JS对象
- 在js中将字符串转换为十六进制
- 试图了解如何使用parseFloat将字符串转换为数字
- 如何在html中将字符串转换为数字?以及如何将变量传递到scriptlet代码中
- 将字符串转换为GWT中的JSON对象(JSNI)
- 如何使用Razor显示模板将字符串转换为html字符串
- 将字符串转换为数组编号Javascript
- js字符串转换为具有两个值的对象
- 转换<a>使用jQuery将文本字符串转换为dom元素
- Jquery-将字符串转换为reg exp对象
- 使用JavaScript将客户端日期/时间字符串转换为JSON日期/时间串
- 将JavaScript字符串转换为整数
- moment js,将EST字符串转换为UTC
- 如何在javascript中将字符串转换为有效日期
- 通过JQuery将字符串转换为JSON