私はRailsアプリケーションでAngularJSを使い始めました.Rails内でhamlテンプレートを使用していたので、クライアントサイドでAngularJSと同じことをしたいと思います。問題は、hamlファイルをどこで読むのか分かりません。angularjs with client side haml
私は投資家のためのモデルを持っています。私は 'show'テンプレートをhamlに変換しようとしています。ここで
はここ
investors.js.coffee
# Setup the module & route
angular.module("investor", ['investorService'])
.config(['$routeProvider', ($provider) ->
$provider
.when('/investors/:investor_id', {templateUrl: '/investors/show.html', controller: 'InvestorCtrl'})
])
.config(["$httpProvider", (provider) ->
provider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content')
])
angular.module('investorService', ['ngResource'])
.factory('Investor', ($resource) ->
return $resource('/investors/:investor_id.json', {}, {
show: {method: 'GET'},
})
)
angular.bootstrap document, ['investor']
を示すために、関連する私のAngularJSコードは私のコントローラAngularJSコード
investors_controller.js.coffee
# Show Investor
window.InvestorCtrl = ($scope, $routeParams, Investor) ->
html = haml.compileHaml({sourceId: 'simple'})
$('#haml').html(html())
investor_id = $routeParams.investor_id
$scope.investor = Investor.show({investor_id: investor_id})
ですバックエンドにはRails JSON APIがあります。ここで
はAngularJSが見て開始する前に、私は.hamlを持っているとtemplateURLにこれを渡して、それをコンパイルするプラグインhaml_coffee_assetsを取得したいと思い結局<script type="text/haml-template" id="simple">
%h1 {{investor.name}}
</script>
<div id="haml"></div>
<h1>{{investor.name}}</h1>
<p>
<b>Total Cost</b>
{{investor.total_cost}}
</p>
<p>
<b>Total Value</b>
{{investor.total_value}}
</p>
<a href='/investors/angular#/investors/{{investor.id}}/edit'>Edit</a>
<a href='/investors'>Back</a>
で、読み込むshow.htmlファイルであります動的なフィールドとコンテンツの変更。
参考:https://github.com/netzpirat/haml_coffee_assets
現在、これはHAMLを変換し、HAMLのidを持つdiv要素に入れます。しかし、AngularJSは、操作が遅すぎるため、hamlコード内の{{investor.name}}を投資家の名前に変更しません。
このようにAngularJSプロジェクト内にクライアントサイドのhamlテンプレートを正しく実装するにはどうすればよいですか?
なぜサーバーサイドのハムレンダリングではないですか?あなたのハムを書いて、いつものように提供して、クライアント側のアプリに変換されたHTMLをリクエストさせてください。このようにして、ハムのフィルターを利用し、角と戦わないようにします。それ以外の場合は、クライアント上でhamlテンプレートを解析した後、手動で角度アプリをブートストラップします。私はそれを試していないが、それは動作することができます。 – jaime
haml形式のRailsビューを使用する場合は、templateUrlに何を入れますか? – map7