noor
noor

Reputation: 681

How to write a function in Ionic popover ?

This is my ionic popover script :

 $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;   
   })

and this is my demo.html

   <ion-popover-view>
        <ion-content>
          <div class="list">
          <button class="item" ng-click=savePost()>Save</button>
          </div>
        </ion-content>
      </ion-popover-view>

but I want to put this function in the code but I am not sure where to put it.

$scope.savePost=function(){

//do something 

console.log ('this is the save post function)

}

Upvotes: 0

Views: 186

Answers (1)

Nere
Nere

Reputation: 4097

Just put your code as below since it still in $scope in the same controller:

$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)

}

Upvotes: 1

Related Questions