2016-06-03 8 views
0

Ich habe eine Ion-Liste und erstelle jedes Ion-Item aus einem ausgewählten Statement. Das Ion-Item-Tag hat ein ng-click Ereignis, das ein modales Fenster aufruft, aber es ruft niemals die show() Methode vom Controller auf. Zum Test stelle ich einen statischen Ionen-Gegenstand ohne DOM-Modifikation und es funktioniert gut. DieseIonic + Angular ng-click keine Bindefunktion aus dynamischem html Element

ist der Code:

Modal Controller

function uib_w_27_modal_controller($scope, $ionicModal) { 
    $scope.modal = $ionicModal.fromTemplate($(".uib_w_27").html(), { 
    scope: $scope, 
    animation: 'slide-in-up' 
    }); 
    $scope.show = function() { 
    $scope.modal.show(); 
    }; 
    $scope.close = function() { 
    $scope.modal.hide(); 
    }; 
    //Cleanup the modal when we're done with it! 
    $scope.$on('$destroy', function() { 
    $scope.modal.remove(); 
    }); 
    // Execute action on hide modal 
    $scope.$on('modal.hidden', function() { 
    // Execute action 
    }); 
    // Execute action on remove modal 
    $scope.$on('modal.removed', function() { 
    // Execute action 
    }); 
}; 

Dynamisches Element

function getFarmaciasSelect(tx, result){ 
    var elem = ''; 
    for (var i = 0; i < result.rows.length; i++) { 
     var row = result.rows.item(i); 
     elem += '<ion-item class="item widget uib_w_24 d-margins item-avatar item-icon-right" data-uib="ionic/list_item_avatar" data-ver="0">' + 
          '<img src="images/Strabburg.jpg">' + 
          '<h2>' + row['nombre'] + '</h2>' + 
          '<p>' + row['calle'] + ' ' + row['altura'] + '</p>' + 
          '<a href="tel:' + row['fijo'] + '"style="text-decoration:none;color:#4CAF50" >' + row['fijo'] + '</a>' + 
          '<i class="icon ion-plus-circled ion" uib-icon-position="right" ng-controller="uib_w_27_modal_controller" ng-click="show()" data-email="[email protected]"></i>' + 
       '</ion-item>'; 
      console.log(elem); 
    } 
    $('#farmacias-list').html(elem); 
} 

Dank für die Hilfe!

+0

Könntest du eine Geige schreiben? Und noch eine zweite Sache: Warum machst du den dynamic-element-part nicht mit einem ng-repeat in deinem html? – Argee

Antwort

1

Wenn Sie wirklich Erzeugungs halten müssen in Ihrem Code dann müssen Sie kompilieren Ihre Inhalte vor zu ‚# farmacias-Liste‘ hinzufügen

$('#farmacias-list').html($compile(elem)($scope)); 

aber auch daran arbeiten, ich werde Sie Verwendung empfehlen collection-repeat zum Generieren von Inhalt im eckigen Kontext.