Angular JS ng-click doesn't work in child element


Tantrop

I'm trying to toggle a variable when an element in the DOM is clicked, but I'm getting some weird behavior.

Full example is here

Essentially, if I click ng on the .options div and then leave the controller on the .options-tab div, the event fires (but for everything inside the .options div ). For some reason I was forced to apply ng-controller again.

<div ng-app ng-controller="Swipe" class="container">
    <div class="options" ng-click="swiped=!swiped2">
         <div ng-controller="Swipe" class="options-tab" ></div>
    </div>
</div>

If you drop it on the desired element, the event will not fire.

<div ng-app ng-controller="Swipe" class="container">
    <div class="options">
         <div ng-controller="Swipe" class="options-tab" ng-click="swiped=!swiped2"></div>
    </div>
</div>
Terry

You have some problems:

  1. Multiple controller declarations create duplicate scopes
  2. ng-click="swiped1=!swiped1"on optionsand options-tabelements (set and then immediately undone)
  3. Your second example is set to, ng-click="swiped=!swiped2"instead ofng-click="swiped2=!swiped2"

Updated working fiddle : http://jsfiddle.net/Xya3f/2/

Related


Angular-js: ng-click doesn't work

Shiva Since I'm very new to angular js, I'm trying to develop small applications, but I'm stuck because ng-click is not working. please help. Thanks in advance. Here is my code: HTML file: <html ng-app="MyApp"> <head> <title>Angular Demo App</title>

ng-click doesn't work in angular js

Himanshu N Tatariya I am using Angular js from one of my projects and calling the "ng-click" function as follows <a ng-click="logout'{{x.ParentEntityId['#text']}}')" target="_blank">{{x.Title["#text"]}}</a> In "x.ParentEntityId['#text']" the value is "7560183

Click event with child element doesn't work

Crest Cruz Sorry if the title is a bit confusing, I'll try to explain it in code. Basically, I created a button to show or hide the cart for an ecommerce site (I'm using woocommerce). Here is the code sample I am working on. HTML tags <div class="crate-status

Angular-js: ng-click doesn't work

Shiva Since I'm very new to angular js, I'm trying to develop small applications, but I'm stuck because ng-click is not working. please help. Thanks in advance. Here is my code: HTML file: <html ng-app="MyApp"> <head> <title>Angular Demo App</title>

element.on('click') on directive in ng-if doesn't work

RWAM I use a directive on the link to provide a modal login if the user is not logged in. And so far, the directive works for all use cases. In the new case, the directive is part of the ng-if section. In the code snippet, the first link works fine, the second

Angular JS: ng-click scope set doesn't work in ng-if

Jeffrey Today, I saw the error in angularjs: When you try to set scope value directly in ng-click, it doesn't work if ng-click tests the same scope value in ng-click -> http://jsfiddle.net/9j2TL/ 26 / angular.module('test', []) .controller('testCtrl', function

AngularJS - ng-click doesn't work on child elements

Kiwanax Ok, I'm trying to create a category browser like eBay using AngularJS. I have root category: <div id='root'> <ul> <li data-ng-repeat='category in categories'> <a href='#' data-ng-bind='category.Name'

AngularJS - ng-click doesn't work on child elements

Kiwanax Ok, I'm trying to create a category browser like eBay using AngularJS. I have root category: <div id='root'> <ul> <li data-ng-repeat='category in categories'> <a href='#' data-ng-bind='category.Name'

ng-click doesn't work in angular js

Himanshu N Tatariya I am using Angular js from one of my projects and calling the "ng-click" function as follows <a ng-click="logout'{{x.ParentEntityId['#text']}}')" target="_blank">{{x.Title["#text"]}}</a> In "x.ParentEntityId['#text']" the value is "7560183

Angular JS - ng-click doesn't work in select option [Chrome]

Joe 82 I have an select optionelement whose purpose is to change the way an ordered list is sorted. Every time I choose another option, it firesng-click <select> <option ng-click="sortType = ['-grade','-year']">Grade</a> <option ng-click="sortType =

Angular-js: ng-click doesn't work

Shiva Since I'm very new to angular js, I'm trying to develop small applications, but I'm stuck because ng-click is not working. please help. Thanks in advance. Here is my code: HTML file: <html ng-app="MyApp"> <head> <title>Angular Demo App</title>

element.on('click') on directive in ng-if doesn't work

RWAM I use a directive on the link to provide a modal login if the user is not logged in. And so far, the directive works for all use cases. In the new case, the directive is part of the ng-if section. In the code snippet, the first link works fine, the second

Angular-js: ng-click doesn't work

Shiva Since I'm very new to angular js, I'm trying to develop small applications, but I'm stuck because ng-click is not working. please help. Thanks in advance. Here is my code: HTML file: <html ng-app="MyApp"> <head> <title>Angular Demo App</title>

element.on('click') on directive in ng-if doesn't work

RWAM I use a directive on the link to provide a modal login if the user is not logged in. And so far, the directive works for all use cases. In the new case, the directive is part of the ng-if section. In the code snippet, the first link works fine, the second

Angular JS ng-click doesn't work in child element

Tantrop I'm trying to toggle a variable when an element in the DOM is clicked, but I'm getting some weird behavior. Full example is here Essentially, if I click ng on the .options div and then leave the controller on the .options-tab div, the event fires (but

AngularJS - ng-click doesn't work on child elements

Kiwanax Ok, I'm trying to create a category browser like eBay using AngularJS. I have root category: <div id='root'> <ul> <li data-ng-repeat='category in categories'> <a href='#' data-ng-bind='category.Name'

ng-click doesn't work in angular js

Himanshu N Tatariya I am using Angular js from one of my projects and calling the "ng-click" function as follows <a ng-click="logout'{{x.ParentEntityId['#text']}}')" target="_blank">{{x.Title["#text"]}}</a> In "x.ParentEntityId['#text']" the value is "7560183