这是我的离子弹出脚本:
$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)
}
答案 0 :(得分: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)
}