2017-02-04 11 views
0

私はこれを機能させるためにさまざまなことを試みました。 私が読んでいる:角膜のクリックが発射されない

ng-click not firing in AngularJS while onclick does

AngularJS : ng-click not working

と、より多くの

HTML:

<div ng-controller="testApp"> 
    <div id="bla"> 
    <button ng-click="obey('bla')">Close</button> 
    <h4>Bla bla bla</h4> 
    </div> 
</div> 

JS:

var testApp = angular.module('testApp', []); 
testApp.controller('testController', function($scope) { 
    $scope.obey = function test(id) { 
    $("#" + id).fadeOut("slow", function() { 
     this.remove() 
    }); 
    }; 
}); 

何らかの理由でdivがまったくフェードアウトしません。

+1

ただ、ヒントをご参照くださいAngularJSを使用している間、あなたはDOM操作を回避する必要があります。http://stackoverflow.com/questions/14994391/thinking-in-angularjs-if-i-have-a-jquery-background 。 AngularJSを使用する場合、jQueryは必須ではありません。 – lin

答えて

5

controllerにあなたのアプリ名を指定しました。これをチェックして。

var testApp = angular.module('testApp', []); 
 
testApp.controller('testController', function($scope) { 
 
    $scope.obey = function test(id) { 
 
    $scope.hide= !$scope.hide; 
 
    }; 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="testApp" ng-controller="testController"> 
 
    <div id="bla"> 
 
    <button ng-click="obey('bla')">Close</button> 
 
    <h4 ng-hide="hide">Bla bla bla</h4> 
 
    </div> 
 
</div>

+0

jsfiddleでこれを行うと、このページで動作しますが動作したくありません。 https://jsfiddle.net/DrevanTonder/sguy6agL/ – DrevanTonder

0

は、それはあなたのコントローラの名前と間違って何か私には思えます。 「LINK

0

は、あなたが角度のアニメーションのためにこの場合

<div ng-controller="testApp"> 
    <div id="bla"> 
    <button ng-click="obey()">Close</button> 
    <h4 ng-show="viewDiv">Bla bla bla</h4> 
    </div> 
</div> 

var testApp = angular.module('testApp', []); 
testApp.controller('testController', function($scope) { 
$scope.viewDiv = true; 
    $scope.obey = function test(id) { 
    $scope.viewDiv = !$scope.viewDiv; 
    }; 
}); 

ng-showまたはng-hideを使用することができます。これを試してみてくださいコントローラ名」

HTML ie。

<body ng-app="testApp"> 
    <div ng-controller="testController"> 
     <div id="bla"> 
     <button ng-click="obey('bla')">Close</button> 
     <h4>Bla bla bla</h4> 
     </div> 
    </div> 
<body> 
0

指定された適切な "NG-アプリ" を参照してくださいと -

<div ng-app="testApp" ng-controller="testController"> 
    <div id="bla"> 
    <button ng-click="obey('bla')">Close</button> 
    <h4>Bla bla bla</h4> 
    </div> 

関連する問題