#javascript #angularjs #ionic-framework
#javascript #angularjs #ionic-framework
Вопрос:
Это мой сценарий ionic popover :
$scope.popover = $ionicPopover.fromTemplateUrl('templates/demo.html', {
scope: $scope,
controller: [$scope,function($scope){
$scope.savePost=function(){
console.log ($scope.$scope.savePost)
}
}]
}).then(function(popover){
$scope.popover = popover;
})
и это мой demo.html
<ion-popover-view>
<ion-content>
<div class="list">
<button class="item" ng-click=savePost()>Save</button>
</div>
</ion-content>
</ion-popover-view>
но я хочу поместить эту функцию в код, но я не уверен, куда ее поместить.
$scope.savePost=function(){
//do something
console.log ('this is the save post function)
}
Ответ №1:
Просто поместите свой код, как показано ниже, поскольку он все еще $scope
находится в том же контроллере:
$scope.popover = $ionicPopover.fromTemplateUrl('templates/demo.html', {
scope: $scope,
controller: [$scope,function($scope){
$scope.savePost=function(){
console.log ($scope.$scope.savePost)
}
}]
}).then(function(popover){
$scope.popover = popover;
})
// savePost() function
$scope.savePost=function(){
//do something
console.log ('this is the save post function)
}