angularjs-ng-click

How can I get the click count

自闭症网瘾萝莉.ら 提交于 2019-12-11 01:51:57
问题 In an anchor tag I would like call one of two different events based on if the user clicked once or twice. However if I implement ng-click and ng-dblclick , both are activated. Is there any way to route to the appropriate listener based on click count? 回答1: You can use a combination of ng-click and $timeout to count the number of times the function has been executed. the code could look like something like this; <a ng-click="clicked()" /> $scope.clickCount = 0; var timeoutHandler = null;

AngularJS - ngSwitch and ngClick not working in ngRepeat

耗尽温柔 提交于 2019-12-10 21:24:50
问题 I want to display the elements of a list thanks to a ngSwitch but I can't figure out how to do with a ngRepeat . I've begun by doing it without a list, just to understand how ngSwitch works and to show you what I want to do, here's a jsFiddle that will help you understand: jdFiffle 1 Then, I try to use a list with ngRepeat but, whatever I try to do, it doesn't work. Here's a second jsFiddle with, this time, the use of a list: jsFiddle 2 It seems that ngClick and ngSwitch don't work when they

ng-click function evaluating on second click (or, unclick)

假如想象 提交于 2019-12-10 19:36:59
问题 --- HTML --- <div class="btn-group menuSection"> <div class="menuGrid" ng-repeat="main in mains"> <button type="button" class="btn btn-default btn-sm btn-block" ng-value="main" btn-radio="main" ng-model="$parent.selectedMain" ng-click="setDish();"/> {{main}} </div> <div class="menuGrid"> <input type="text" class="form-control input-sm" ng-model="mainOtherText" ng-show="selectedMain == 'Other'" placeholder="enter other here"/> </div> test : {{mainDish}} </div> --- JS --- $scope.setDish =

A function like: ng-click=“alert('Clicked')”

牧云@^-^@ 提交于 2019-12-10 14:57:18
问题 For a mockup I need a simple mechanism like ng-click="alert('Clicked')" but the code above is not working, can someone help me? I don't want to touch the Controller.. 回答1: As far as I know, ng-click works only within your $scope . So you would only be able to call functions, defined in your $scope itself. To use alert, you may try accessing the window element, just by using window.alert('Clicked') . EIDT: Thanks to Ibrahim. I forgot. You shouldn't be able to use window.alert , as far as you

prioritize ngclick over nghref in <a> elements

荒凉一梦 提交于 2019-12-10 14:53:03
问题 tl;dr : How can I force angular to only execute the ngclick directive in an <a> element without emptying/removing the href ? My site has some custom behavior on some elements (modal opens, location bar updates, etc.) but for SEO indexing I also need it to be an <a> element with an href attribute containing a valid link. Such as: <a href="/{{item.url}}" ng-click="doCustomStuff(item)">some link</a> However, angular also executes the href and the routing makes my custom ng-click logic useless.

How to test if event.target.hasClass() using angularJS and jqlite?

牧云@^-^@ 提交于 2019-12-10 13:57:13
问题 After a click pass the event to ctrl. I want to write a conditional that will return true if the element.target has the class modal-click-shield Question: How can I use .hasClass() with event.target using angulars' jqlite ? Problem: Currently I'm getting a type error saying that: $scope.exitModal = function(event){ // Return to current page when exiting the modal, via UI. // After state return, should set focus on the matching link. var target = event.target; console.log(target.hasClass(

ngclick deprecated. Popular alternative or solution?

亡梦爱人 提交于 2019-12-10 13:23:43
问题 I'm new to angular. ng-click seems like a pretty core directive, I don't understand how you can make an app without ng-click. Am I missing something? Apparently it's deprecated. And the docs point me to fastclick but that's not an angular implementation. Is there a popular non-deprecated way of doing what ng-click did? I couldn't find any popular packages on bower for this. Thanks. 回答1: ng-click is only being deprecated within the ngTouch module due to delays when used in mobile browsers.

How can I pass a parameter to an ng-click function?

倖福魔咒の 提交于 2019-12-08 15:00:29
问题 I have a function in my controller that looks like the following: AngularJS: $scope.toggleClass = function(class){ $scope.class = !$scope.class; } I want to keep it general by passing the name of the class that I want to toggle: <div class="myClass">stuff</div> <div ng-click="toggleClass(myClass)"></div> But myClass is not being passed to the angular function. How can I get this to work? The above code works if I write it like this: $scope.toggleClass = function(){ $scope.myClass = !$scope

AngularJS ng-click on li icon

心不动则不痛 提交于 2019-12-08 08:21:45
问题 I have this code <div ng-repeat="names in mitypes = (mitype | filter:{parentid:0}:true)"> <li ng-click="newObject[names.id]=!newObject[names.id]"> <label ng-click="selectedlist[names.id]=!selectedlist[names.id]">{{names.id}} </label> </li> </div> </div> Its tree of ul li elements. So i want to have 2 any event of click: 1. Click li ng-click for open/close tree branch 2. Click label ng-click for select tree node li element have css style: li { list-style-type: none; background-repeat: no

Angular ng-class via ng-click inside ng-repeat

隐身守侯 提交于 2019-12-08 03:13:42
问题 Edit: The answers below haven't taken into account the +1 function that is also being applied. Still looking for how I can make both happen. I have an ng-click function that is called on a button within an ng-repeat, but each time one of the buttons is clicked it causes the class to change on all the buttons. How can I fix my code to make it so only the clicked button itself changes? (Keep in mind, the numbers work fine, it's just the classes that change all together.) The Angular controller