【问题标题】:Infinite template loading using Angular JS routeprovider使用 Angular JS 路由提供程序进行无限模板加载
【发布时间】:2013-02-24 15:59:20
【问题描述】:

已修复检查 xhr 请求修复了无限循环

get '/about' do
    erb :about, layout: !request.xhr?
end

我正在使用 Angular js 和 sinatra 来创建一个页面。 Angular 正在处理我的路线并调用模板

app.config(['$routeProvider', function ($routeProvider) {
    $routeProvider.
        when('/home', {templateUrl: '/home'}).
        when('/about', {templateUrl: '/about'}).
        when('/work', {templateUrl: '/work'}).
        when('/blog', {templateUrl: '/blog'}).
        when('/contact', {templateUrl: '/contact'}).
        otherwise({redirectTo: '/'});
}]);

当我转到 /#/blog 时,模板加载正常。内容由 sinatra 提供

get '/blog' do
    'This is the work page!'
end

但是,在执行 about 页面时,我得到了无限的视图加载。关于页面由

提供
get '/about' do
    erb :about
end

【问题讨论】:

  • 我所能做的就是确认您的角度代码看起来不错。对 erb 不太熟悉,不知道 erb :about 是做什么的
  • 不要将:erb about 放在get 循环中。那是另一页,位置为about。这就是你得到无限循环的原因。

标签: ruby angularjs sinatra erb routes


【解决方案1】:
get '/about' do
    erb :about, layout: !request.xhr?
end

前面的代码加载了包含 Angular js 代码的布局。 js 代码再次调用 /about 并重复。由于来自 Angular js 路由的调用是 xhr,因此检查它解决了问题。

【讨论】:

    猜你喜欢
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 2013-03-18
    • 2014-07-22
    • 1970-01-01
    • 1970-01-01
    • 2017-08-12
    • 1970-01-01
    相关资源
    最近更新 更多