0

ボタンでdom要素のinterhtmlを変更しています。そして、ボタンがクリックされたときに、別のコントローラー機能を起動したいと思います。そんな感じ。...しかし動作していません:)。

$scope.addBtn = function() {
   $('domtarget').html('<button ng-click="removeButton();"></button>');
}

$scope.removeBtn = function() {
   $('domtarget').html('');
}

修正を提案してください:)

4

1 に答える 1

1

コントローラー内で DOM を変更しないでください

<div ng-show="showMe"></div>
<button ng-click="showMe = !showMe;anotherAction()">Switch</button>
<button ng-click="someOtherAction()">Switch2</button>

.

function SomeCtrl($scope) {
    $scope.showMe=true;
    $scope.anotherAction = function () {
        alert("gotcha");
    };
    $scope.someOtherAction = function () {
        $scope.showMe = !$scope.showMe;
        $scope.anotherAction();
    };
}

要素を条件付きで非表示/表示するには、ng-showまたはng-hideを使用します。
クリック時にイベントを発生させるには、ng-clickを使用します

于 2013-01-22T12:41:29.013 に答える