【问题标题】:AngularJS routingAngularJS 路由
【发布时间】:2014-08-28 08:59:31
【问题描述】:

我有一些账户路线:

.when('/accounts', {
    templateUrl: 'views/accounts.html',
        controller: 'AccountsCtrl'
    })
.when('/accounts/:accountId', {
    //templateUrl: 'views/account-details.html', // adding this i get a SyntaxError: Unexpected token < and shows my ng-view within ng-view just weird
    //controller: 'AccountsDetailCtrl'
 })

然后转到/accounts/:account 使用不适合的帐户模板,因为它有一个显示所有帐户的表格。我想将其发送到新路由,但同时想将 userId 作为参数传递。

有没有办法将应用发送到带有 url 参数的新路由?

编辑

为了澄清一些事情,我知道当我成功地将应用程序发送到没有错误的新路线时,我可以使用 $routeParams。但是,如果我将模板设置为'/accounts/:accountId',则在上面的代码中注释我会收到错误。

SyntaxError: Unexpected token <
    at eval (native)
    at https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js:2:2620
    at Function.m.extend.globalEval (https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js:2:2631)
    at m.ajaxSetup.converters.text script (https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js:4:26387)
    at Pc (https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js:4:18104)
    at x (https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js:4:21525)
    at b (https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js:4:25897)
    at Object.send (https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js:4:26001)
    at Function.m.extend.ajax (https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js:4:21302)
    at Function.m._evalUrl (https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js:4:22522) <div class="col-md-10 col-md-offset-2 main ng-scope" ng-view=""> 

我不知道为什么。我的account-details.html 模板只有Hello world

【问题讨论】:

    标签: angularjs angularjs-service angularjs-routing


    【解决方案1】:

    你可以使用 $routeParams

    请看; $routeParams

    如何使用; https://stackoverflow.com/a/11535887/929902

    【讨论】:

    • 我知道我可以使用 $routeParams 但我需要在新路由中使用它并执行类似.when('/accounts-one/:accountId', {templateUrl: &lt;tmplt route&gt;, controller: &lt;ctrl&gt; 的操作我得到 SyntaxError: Unexpected token
    猜你喜欢
    • 1970-01-01
    • 2017-08-29
    • 1970-01-01
    • 2017-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多