我試圖將一個組件的值傳遞給另一個組件。AngularJS - 將值傳遞給組件
位置列表
<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
的位置ID是:
自行車名單
自行車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>
輸出:
的位置ID是:
問題
- 如何獲取locationId到自行車列表?
謝謝你。爲我省下了很多努力 –