我是 angularjs 的新手,下面的部分总是让我很困惑
angular.module('bookYourSeatApp', [])
.factory('seats', SeatsFactory)
.controller('mainCtrl', MainCtrl);
我想获得路由参数,我试过了
function SeatsFactory($rootScope, $timeout, $routeParams) {
和
function MainCtrl(seats, $routeParams) {
并在其他几个地方插入 $routeparams ,我到处都是错误。代码在小提琴中。如何在下面的代码中注入 $routeparams?
angular.module('bookYourSeatApp', [])
.factory('seats', SeatsFactory)
.controller('mainCtrl', MainCtrl);
function SeatsFactory($rootScope, $timeout) {
//more code
var factory = {
map: seats,
setSeats: setSeats,
select: selectSeats,
checkedSeats: checkedSeats,
availCount: {},
setAvailCount: function(count) {
console.log('avail', count);
checkSelected(count);
}
};
return factory
}
function MainCtrl(seats) {
// console.log($routeParams);
var vm = this;
angular.extend(vm, {
seats: seats,
selectionCount: [//[0,1,2,3,4],[
{id: 0, val: 0}, // object for two-way binding
],
selectedCount: 0
});
vm.selectedCount = vm.selectionCount[0];
seats.setAvailCount(vm.selectedCount);
}