如何在Ionic popover中编写函数?

时间:2016-10-14 02:56:47

标签: javascript angularjs ionic-framework

这是我的离子弹出脚本:

 $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 个答案:

答案 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)

}