私は ngRoute と Angular をいじっていますが、coshed アイテムの詳細ページに移動するために、ビューでアイテムを選択しようとすると問題があるようです:
<h1>Select Item</h1>
<ul>
<li ng-repeat="item in vm.items">
<a ng-click="vm.setSelectedItem(item)" ng-href="#/first/{{item.id}}">
{{item.thing}}
</a>
</li>
</ul>
vm.selectedItem
「詳細」ページにレンダリング/表示されないのはなぜですか?
var app=angular.module("myApp", ['ngRoute']);
app.config(function($routeProvider){
$routeProvider
.when('/first', {
templateUrl: 'first.html',
controller: 'FirstCtrl',
controllerAs:'vm'
})
.when('/first/:id', {
templateUrl: 'firstWithItem.html',
controller: 'FirstCtrl',
controllerAs:'vm'
})
.otherwise({
redirectTo: '/first'
});
});
app.controller("FirstCtrl", function() {
var vm = this;
vm.items = [{id:1, thing:"Beer"},{id:2, thing:"Grass"}];
vm.selectedItem = null;
vm.setSelectedItem = SetSelectedItem;
function SetSelectedItem(item) {
this.selectedItem = item;
}
});