0

I have tried many different things to try to get this to work. I have read:

ng-click not firing in AngularJS while onclick does

AngularJS : ng-click not working

and a lot more

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()
    });
  };
});

For some reason the div does not fade out at all.

1
  • 2
    Just a hint, you should avoid DOM manipulations while using AngularJS please refer: stackoverflow.com/questions/14994391/…. jQuery is not required/recommend when using AngularJS. Commented Feb 4, 2017 at 12:46

4 Answers 4

8

You specified your app name in controller. check this.

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>

Sign up to request clarification or add additional context in comments.

1 Comment

If I do that on jsfiddle it does not want to work though it works on this page. jsfiddle.net/DrevanTonder/sguy6agL
0

Seems to me it's something wrong with name of your controller. Try this:

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

Comments

0

you can use a ng-show or ng-hide in this case

<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;
  };
});

for angular animation - refer LINK

Comments

0

specified proper "ng-app" and "ng-controller" name

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>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.