टेम्पलेट, आप घटक कोड में अपने डेटा प्राप्त करना चाहते करने के लिए जगह नहीं है। लगता है जैसे आप किसी अवलोकन के जैसे कुछ उपयोग करना चाहते हैं, जिससे आप स्रोत में प्रत्येक आइटम के लिए एक और अवलोकन कर सकते हैं। यह एक http एपीआई कॉल का रिटर्न या (fiddle):
var ids = ["a", "d", "c"];
var lookupValues = { "a": 123, "b": 234, "c": 345, "d": 456 };
// given an id
function fakeApiCall(id) {
// given an id, return an observable with one entry: an object consisting
// of an 'id' property with that id value and a 'lookup' property with the
// value from lookupValues for that id
return Rx.Observable.just({ id: id, lookup: lookupValues[id] });
}
var o1 = Rx.Observable.from(ids); // 'a, d, c
var o2 = o1.flatMap(x => {
// here we get each value from o1, so we do an api call and return
// an observable from each that will have the values in that
// observable combined with all others to be sent to o2
return fakeApiCall(x);
});
o2.subscribe(x => {
document.write(JSON.stringify(x) + "<br/>");
});
// result:
// {"id":"a","lookup":123}
// {"id":"d","lookup":456}
// {"id":"c","lookup":345}
स्रोत
2016-08-05 12:20:20
एक अजीब आवश्यकता की तरह लगता है। आप क्या खत्म करने की कोशिश कर रहे हैं? –
@ गुंटर ज़ोचबॉयर उदाहरण के लिए, कुछ जटिल तरीके से आइटम गुणों का डिस्प्ले नाम उत्पन्न करें। यह बिल्कुल अजीब नहीं है। – user2061057
इसे कोड में करें और इसे प्रत्येक 'आइटम' को असाइन करें और फिर इसे' * ngFor' के अंदर उपयोग करें। टेम्पलेट बाइंडिंग से इस तरह के फ़ंक्शन कॉल को हतोत्साहित किया जाता है। –