2017-03-28 17 views
5

मैं एक घटक से दूसरे घटक में एक मूल्य पारित करने की कोशिश कर रहा हूं।कोणीय जेएस - घटक को पास मूल्य

स्थान सूची

<div uib-accordion-group class="panel-default" heading="{{location.name}}" ng-repeat="location in $ctrl.locations"> 
    <p>This is from location list: {{location.id}}</p> 
    <bike-list locationId="{{location.id}}"></bike-list> 
</div> 

आउटपुट:

इस स्थान सूची से है: 1

स्थान आईडी है:

बाइक सूची

बाइक-list.component.js

angular 
.module('bikeList') 
.component('bikeList', { 
    templateUrl: 'bike-list/bike-list.template.html', 
    controller: ['$rootScope', function ($rootScope) { 
     var self = this; 
     self.bikes = $rootScope.currentBikes; 

    }], 
    bindings: { 
     locationId: '<' 
    } 
}); 

बाइक-list.template.html

<head> 
    <meta charset="UTF-8"> 
    <title>Title</title> 
</head> 
<body> 
    <p>Location id is : {{$ctrl.locationId}}</p> 
</body> 

आउटपुट:

स्थान आईडी है:

प्रश्न

  • मैं स्थान कैसे प्राप्त कर सकता हूं बाइक सूची में?

उत्तर

3

में पाया जा सकता मैं

को <bike-list locationId="{{location.id}}"></bike-list> बदल
<bike-list location-id="location.id"></bike-list> 

जो मेरी समस्या का हल!

आउटपुट:

इस स्थान सूची से है: 1

स्थान आईडी है: 1

+1

इसके लिए धन्यवाद। मुझे बहुत प्रयास बचाया –

1

इसके बजाय <bike-list locationId="{{location.id}}"></bike-list> परिवर्तन यह करने के लिए

<bike-list location-id="$ctrl.location.id"></bike-list> 

कोणीय सामान्य attrs और आप here

काम कर उदाहरण में इसके बारे में और अधिक पढ़ सकते here

+0

एक त्रुटि का कारण बनता है कि। उत्पादन अब है: इस स्थान सूची से है: 1 स्थान आईडी है: {{$ ctrl.locationId}} – alexdriedger

+0

यहाँ एक उदाहरण है https://plnkr.co/edit/U1AxlM1Quthv7T49ergD?p=preview – fernando