【问题标题】:Angular and Sinatra, templates loaded over ajax are not interpolatedAngular 和 Sinatra,通过 ajax 加载的模板不会被插值
【发布时间】:2014-01-30 23:28:08
【问题描述】:

所以,我正在尝试设置我的第一个 Angular 应用程序,问题是通过 ajax 检索的模板没有被 Angular 插值。我正在使用 Ruby Sinatra 框架进行简单的 HTTP,这里是主要部分代码: index.html

<div ng-view></div>

main.js

var app = angular.module('myApp', ['ngRoute']);

app.config(function($routeProvider) {
    $routeProvider.when('/', {
        templateUrl: 'templates/home.html',
        controller: 'HomeController'
    })
})

app.controller('HomeController', function($scope) {

});

home.html

{{ 1 + 1 }}

Sinatra 应用程序.rb

#!/usr/bin/env ruby

require 'sinatra'

class HelloWorldApp < Sinatra::Base
  get '/' do
    send_file 'index.html'
  end

  get '/js/:name' do
    send_file "js/#{params[:name]}"  
  end

  get '/templates/:name' do 
    send_file "templates/#{params[:name]}"
  end
end

现在,当我加载 http://localhost:9292/ 时,我得到的是 {{ 1 + 1 }} 而不是 2。有什么问题?

【问题讨论】:

    标签: javascript ajax angularjs sinatra


    【解决方案1】:
    angular.element(document).ready(function(){ angular.bootstrap(document, ['myApp']); });

    【讨论】:

      猜你喜欢
      • 2016-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-29
      相关资源
      最近更新 更多