从单击传递数据以加载模态

时间:2016-02-20 14:18:13

标签: javascript angularjs ionic-framework

如何从调用中传递数据以加载模态,即此变量,以便我可以在我的控制器上使用它来在我的查询中使用它

$scope.compareMe = function(Data) {
    console.log($scope.cannedLst.name)
    var c = $scope.cannedLst.name;
    $scope.Data = c;
    $scope.modal.show();
  }

1 个答案:

答案 0 :(得分:1)

在使用$ionicModal的控制器中,您可以将数据作为范围变量传递

//your main controller
.controller('MyController', function($scope, $ionicModal) {

//you function to get data and call modal
  $scope.compareMe = function(Data) {
    console.log($scope.cannedLst.name)
    var c = $scope.cannedLst.name;
//this is the data we're passing
    $scope.Data = c;
    $scope.modal.show();
  }

//modal configuration (may be 'templateString')
  $ionicModal.fromTemplateUrl('my-modal.html', {
//here it states that inside the modal $scope will be == data you've passed
    scope: $scope.Data,
    animation: 'slide-in-up'
  }).then(function(modal) {
    $scope.modal = modal;
  });