gpt4 book ai didi

javascript - Angular ng-repeat 错误

转载 作者:行者123 更新时间:2023-11-30 17:28:37 25 4
gpt4 key购买 nike

所以我的 HTML 是:

<div class="checkbox" ng-repeat="test in tests">
<a ui-sref="test{{id: test._id}}"><pre>{{test._id}}</pre></a>
</div>

我在 app.js 中的路由器配置

myApp.config(function($stateProvider, $urlRouterProvider){
$urlRouterProvider.otherwise("");
$stateProvider
.state('main', {
url: ""
})
.state('new', {
url: "/new",
templateUrl: "templates/new.html"
})
.state('test', {
url: "/tests/:id",
templateUrl: "templates/test.html"
})
});

我有一个控制台抛出的错误

Error: Syntax Error: Token ':' is an unexpected token at column 3 of the expression [id: test._id] starting at [: test._id]. at Error (native) What the problem?

最佳答案

发送参数的语法就像一个函数——将它们括在大括号中 test({..})

<div class="checkbox" ng-repeat="test in tests">
<a ui-sref="test({id: test._id})"><pre>{{test._id}}</pre></a>
</div>

类似问题:Dynamically constructed ui-sref attribute in ui-router

关于javascript - Angular ng-repeat 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23677052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com