0

請問如何將文本發送到模態視圖和模型視圖文本到主屏幕?在我的演示中,我有一個文本字段和按鈕。我需要發送輸入文本到模態和模態我有一個文本框和按鈕我需要在主屏幕上發送輸入字段值。我們如何將主屏幕與模態屏幕交流。我需要將數據發送到模態從角 這裏模式得到的數據是我的代碼:如何將文本發送到模態和模型文本到主屏幕?

http://codepen.io/anon/pen/BNabez

var app =angular.module('ionicApp',['ionic']); 
app.controller('cntr',function($scope,$http,$ionicModal){ 
$ionicModal.fromTemplateUrl('templates/modal.html', { 
    scope: $scope 
    }).then(function(modal) { 
    $scope.modalFirst = modal; 
    }); 
    $scope.openmodel=function(){ 
    // alert('d'); 
    $scope.modalFirst.show() 
    } 


}) 

回答

2

你有餘地,要聲明變量,然後將其綁定 我已編輯您codepen

http://codepen.io/anon/pen/OVJGxm

HTML:

<html ng-app="ionicApp"> 
    <head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> 

    <title>Sign-in, Then Tabs Example</title> 

    <link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet"> 
    <script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script> 

    </head> 

    <body ng-controller="cntr"> 

    <ion-view> 
    <ion-header-bar class="bar-balanced"> 
     <h1 class="title">load data before modal show</h1> 
    </ion-header-bar> 
    <ion-content scroll="false"> 

    <button ng-click="openmodel()">send data on popup screen </button> 
     <input type="text" placeholder="Say Something" ng-model="input.saySomething"/> 
     <h1>{{item.text}}</h1> 
    </ion-content> 
    <ion-footer-bar class="bar-balanced"> 
     <h1 class="title">Footer</h1> 
    </ion-footer-bar> 
</ion-view> 
    <script id="templates/modal.html" type="text/ng-template"> 
     <ion-modal-view> 
     <ion-header-bar class="bar-balanced"> 
     <h1 class="title">departure</h1> 
    </ion-header-bar> 
    <ion-content> 
     <h1>naveen+{{input.saySomething}}</h1> 
     <input type="text" ng-model="item.text"> 
     <button>send to main screen</button> 
    </ion-content> 
    <ion-footer-bar class="bar-balanced"> 
     <h1 class="title">Footer</h1> 
    </ion-footer-bar> 
     </ion-modal-view> 
    </script> 
    </body> 
</html> 

JS:

var app =angular.module('ionicApp',['ionic']); 
app.controller('cntr',function($scope,$http,$ionicModal){ 
    $scope.item={}; 
    $scope.input={}; 
$ionicModal.fromTemplateUrl('templates/modal.html', { 
    scope: $scope 
    }).then(function(modal) { 
    $scope.modalFirst = modal; 
    }); 
    $scope.openmodel=function(){ 
    // alert('d'); 
    $scope.modalFirst.show() 
    } 


}) 
+0

@ f5ed你能解釋更多 – user944513

+0

以及你已經綁定到輸入{{input.saySomething}}所以它指的是財產的對象輸入NG saySomething -model將創建變量/屬性(如果在範圍中不可用),但它不能創建對象及其屬性(我認爲),因此您需要爲範圍內的對象定義 –

+0

行得通! – user944513