2016-09-21 83 views
1

例如值發送到角控制,我有HTML,將只顯示在彈出我可以通過JavaScript在運行時

<div id="popup1" style="display: none; width: 600px; height: 400px; overflow: hidden"> 
<div ng-controller="DataBindingCtrl"> 



    <div rel="title"> 
     Show or Update Image 
    </div> 
    <div rel="body" style="padding: 10px; line-height: 150%"> 
     <div > 
      <img src="https://upload.wikimedia.org/wikipedia/commons/a/ac/No_image_available.svg" style="float: left; background-color: white; width: 250px; height: 320px; border: 1px solid silver; margin: 5px;"/> 
     </div> 
     <div class="w2ui-field w2ui-span3"> 
      <label>Files:</label> 
      <div> 
       <form class ="form-horizontal"> 
        <input id="file" style="width: 100px" />{{selBookId}} 
        <input id="currentRecord" type="text" ng-model="currentRecordText" ng-model-instant> 
        {{currentRecordText}} {{idRec}} 
       </form> 
      </div> 
     </div> 
    </div> 

    @*<div rel="buttons"> 
     <button class="btn" onclick="$('#popup2').w2popup()">Switch to Popup 2</button> 
    </div>*@ 
</div> 

我想爲設置一個值idRec當用戶點擊彈出窗口按鈕。

這是可能的,什麼是正確的方法?

+0

我想你可以有它的'NG-model'指向'idRec' – Rajesh

+2

一個隱藏的文本字段,當你需要使用jQuery與角度很最好把jQuery的東西放在指令中。然後,您將能夠將所需的任何參數從視圖傳遞到指令,並將它們與您的jQuery代碼一起使用。 – Lex

+0

你能提供jsfiddle嗎? –

回答

1

我認爲你想從jQuery函數改變範圍變量。

您可以在您的Angular控制器中使用jQuery函數,如下所示。

app.controller('AppCtrl', function($scope) { 
    $('.popupCall').on('click', function(){ 
     $scope.idRec= "newValue"; 
     $scope.$apply(); 
     $('#popup2').w2popup(); 
    }); 
} 

<button class="btn popupCall">Switch to Popup 2</button> 
+0

謝謝 - 你是對的,你給我一個正確的方法! – Alexander

+0

但是 - 據我所知,在angularjs控制器內部沒有辦法發送數據。我們需要從控制器主體中截取事件而沒有任何變體... – Alexander

+0

如果您想要通過jquery事件調用並將值傳遞給Angular函數,您可以使用angular.element嘗試並將它與google進行比較。 –

0

你可以做的是在你的控制器上添加一個函數。

DataBindingCtrl

$scope.idRec = ''; 
$scope.updateIdRec = function() { 
    $scope.idRec= "newValue";  
    $('#popup2').w2popup(); 
}; 

HTML

<button class="btn" ng-click="updateIdRec()">Switch to Popup 2</button> 
相關問題