将一些功能添加到一个控制器角
我试图添加另一个功能到我的控制器,但它不断打破控制器。将一些功能添加到一个控制器角
这里是我的代码:
.controller('ClimbController', [
\t '$scope', '$stateParams', 'Climbs', function(
\t $scope, $stateParams, Climbs) {
\t \t var climb_id = $stateParams.climbId;
\t \t var areaId = $stateParams.areaId;
\t \t if (!isNaN(climb_id)) {
\t \t \t climb_id = parseInt(climb_id);
\t \t }
\t \t if (!isNaN(areaId)) {
\t \t \t areaId = parseInt(areaId);
\t \t }
\t \t $scope.selected_ = {};
\t \t $scope.items = [];
\t \t $scope.details = true;
\t \t // looping though all data and get particular product
\t \t $scope.selectClimb = function(areas){
\t \t \t areas.forEach(function(data) {
\t \t \t if(data._id == climb_id){
\t \t \t \t $scope.selected_ = data;
\t \t \t }
\t \t \t });
\t \t }
\t \t // get all posts // try some function to get a single produt from server
\t \t $scope.getPosts = function(){
\t \t \t Climbs.getPosts()
\t \t \t .success(function (data) {
\t \t \t \t // data = feed.json file
\t \t \t \t var climbs = [];
\t \t \t \t data.areas.map(function(area) {
\t \t \t \t \t if (area._id === areaId) {
\t \t \t \t \t \t climbs = area.climbs;
\t \t \t \t \t }
\t \t \t \t });
\t \t \t \t $scope.selectClimb(climbs);
\t \t \t })
\t \t \t .error(function (error) {
\t \t \t \t $scope.items = [];
\t \t \t });
\t \t }
\t \t $scope.getPosts();
}
])
我定义这个添加到它:
.controller('MyCtrl', function($scope, $ionicModal) {
$ionicModal.fromTemplateUrl('test-modal.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
});
$scope.openModal = function() {
$scope.modal.show();
};
$scope.closeModal = function() {
$scope.modal.hide();
};
//Cleanup the modal when we're done with it!
$scope.$on('$destroy', function() {
$scope.modal.remove();
});
// Execute action on hide modal
$scope.$on('modal.hidden', function() {
// Execute action
});
// Execute action on remove modal
$scope.$on('modal.removed', function() {
// Execute action
});
});
当我尝试添加该至它打破了它的代码。我需要将其添加为另一个函数或将其添加到代码所需的任何内容。
非常感谢
假设你要合并'MyCtrl
功能为ClimbController
然后
.controller('ClimbController', ['$scope', '$stateParams', 'Climbs','$ionicModal', function($scope, $stateParams, Climbs,$ionicModal) {
var climb_id = $stateParams.climbId;
var areaId = $stateParams.areaId;
if (!isNaN(climb_id)) {
climb_id = parseInt(climb_id);
}
if (!isNaN(areaId)) {
areaId = parseInt(areaId);
}
$scope.selected_ = {};
$scope.items = [];
$scope.details = true;
// looping though all data and get particular product
$scope.selectClimb = function(areas){
areas.forEach(function(data) {
if(data._id == climb_id){
$scope.selected_ = data;
}
});
}
// get all posts // try some function to get a single produt from server
$scope.getPosts = function(){
Climbs.getPosts()
.success(function (data) {
// data = feed.json file
var climbs = [];
data.areas.map(function(area) {
if (area._id === areaId) {
climbs = area.climbs;
}
});
$scope.selectClimb(climbs);
})
.error(function (error) {
$scope.items = [];
});
}
$scope.getPosts();
$ionicModal.fromTemplateUrl('test-modal.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
});
$scope.openModal = function() {
$scope.modal.show();
};
$scope.closeModal = function() {
$scope.modal.hide();
};
//Cleanup the modal when we're done with it!
$scope.$on('$destroy', function() {
$scope.modal.remove();
});
// Execute action on hide modal
$scope.$on('modal.hidden', function() {
// Execute action
});
// Execute action on remove modal
$scope.$on('modal.removed', function() {
// Execute action
});
}])
多数民众赞成它是}我有我错误的地方,它正在捣毁:)和}])现在关闭。 – user1155141
非常感谢你 – user1155141
@ user1155141听起来很棒,你的问题已经解决了投票它 –
什么突破?你想把'Myctrl'所有功能都包含在上面的控制器中? –