के साथ angularjs मैंने अपने रेल ऐप के साथ एंगुलरजेएस का उपयोग करना शुरू कर दिया है और जैसा कि मुझे रेल के अंदर हैमल टेम्पलेट्स का उपयोग करने के लिए उपयोग किया जाता है, मैं क्लाइंट साइड पर एंगुलरजेएस के साथ ऐसा करना चाहता हूं। समस्या यह है कि मुझे नहीं पता कि हैमल फ़ाइल में कहां पढ़ना है।क्लाइंट साइड हैम
मेरे पास निवेशकों के लिए एक मॉडल है और मैं 'शो' टेम्पलेट को हॉल पर बदलने की कोशिश कर रहा हूं क्योंकि यह शुरू करना सबसे आसान है।
यहाँ मेरी AngularJS कोड दिखाने से संबंधित है
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 कोड है
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})
बैकएंड में मेरे पास एक रेल JSON API है।
यहाँ show.html फ़ाइल
<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>
अंततः में इसे पढ़ता है मैं एक .haml है और templateURL को यह गुजरती हैं और haml_coffee_assets यह संकलित करने के लिए प्लगइन प्राप्त करना चाहते हैं इससे पहले कि AngularJS को देख शुरू होता है गतिशील क्षेत्रों और सामग्री बदल रहा है।
रेफरी: https://github.com/netzpirat/haml_coffee_assets
वर्तमान में यह haml बदलने और haml की आईडी के साथ div में डाल देंगे। हालांकि AngularJS निवेशक के नाम पर हैमल कोड के भीतर {{investor.name}} को नहीं बदलेगा क्योंकि ऑपरेशन में बहुत देर हो चुकी है।
इस तरह एंगुलरजेएस प्रोजेक्ट के भीतर मैं क्लाइंट साइड हैमल टेम्पलेट्स को सही ढंग से कैसे कार्यान्वित करूं?
सर्वर-साइड हैमल प्रतिपादन क्यों नहीं? सामान्य रूप से अपने हैमल को लिखें और सेवा दें और क्लाइंट साइड ऐप को परिवर्तित एचटीएमएल का अनुरोध करें। इस तरह आप हैमल के फिल्टर का लाभ उठाते हैं और कोणीय से लड़ते नहीं हैं। अन्यथा, क्लाइंट पर हैमल टेम्पलेट्स को पार्स करने के बाद आप मैन्युअल रूप से कोणीय ऐप बूटस्ट्रैप करेंगे। मैंने कोशिश नहीं की है लेकिन यह काम कर सकता है। – jaime
तो अगर मैं हैम प्रारूप में रेल दृश्यों का उपयोग करना चाहता था तो मैं टेम्पलेट यूआरएल में क्या रखूंगा? – map7