angularjs-ng-click

AngularJS - how to use ng-click without submitting the form?

你说的曾经没有我的故事 提交于 2020-01-01 07:42:48
问题 I have a form that has both ng-click and ng-submit. ng-submit is meant for the submission, while ng-click calls a separate function like upload, etc. How do I make sure that ng-click does not accidentally submits the form? thank you! 回答1: ngClick does not submit the form. Sometimes, you can have problems because you have two button elements in your form , and they both submit it. To avoid that, specify the type "button" on it. Example : function demo ($scope) { $scope.doSubmit = function () {

AngularJS - how to use ng-click without submitting the form?

点点圈 提交于 2020-01-01 07:42:04
问题 I have a form that has both ng-click and ng-submit. ng-submit is meant for the submission, while ng-click calls a separate function like upload, etc. How do I make sure that ng-click does not accidentally submits the form? thank you! 回答1: ngClick does not submit the form. Sometimes, you can have problems because you have two button elements in your form , and they both submit it. To avoid that, specify the type "button" on it. Example : function demo ($scope) { $scope.doSubmit = function () {

AngularJS: ng-click on img? Manipulating images (kind of gallery-like) with jQuery?

萝らか妹 提交于 2020-01-01 04:22:14
问题 Should ng-click work with img tag ? <img ng-src="img" ng-click="openNewWindow(url)/> myFunction is defined in controller and is $scope available … Nothing gets called; any ideas? (I would like to open a new tab/window when image is clicked, but I don't even get into my function) Thanks for any info EDIT I probably rushed myself when first asking this question. I know now why it doesn't work in my case: I am manipulating images with jQuery for some kind a 'gallery' effect … (if anyone has an

ng-click not working with ng-if

旧时模样 提交于 2019-12-31 22:39:46
问题 Why does the second button not work, when ng-if is used? I want to realize a button that is present only when the model value is set / not ""/ not null. Template: <input type="text" ng-model="blub"/> <br/> <button ng-click="blub = 'xxxx'">X</button> <br/> <button ng-click="blub = 'yyyy'" ng-if="blub.length">Y</button> Controller: angular.module('test', []) .controller('Main', function ($scope) { // nothing to do here }); To play around: JSFiddle 回答1: Use ng-show Instead of ng-if . That should

jQuery not working with ng-repeat results

ぐ巨炮叔叔 提交于 2019-12-29 04:01:05
问题 I am using ng-repeat to build an accordion using jQuery and TB. For some reason, this is working perfectly when hardcoded but fails to trigger on click when inside of the ng-repeat directive. I was thinking that the issue is from jQuery not binding elements loaded in after the fact. So, I figured that instead of loading the script on page load, it would be better to load the function on .success when the data is returned. Unfortunately, I cannot figure out how to make this work. Test page :

Adding parameter to ng-click function inside ng-repeat doesn't seem to work

风格不统一 提交于 2019-12-27 10:29:29
问题 I have a simple loop with ng-repeat like this: <li ng-repeat='task in tasks'> <p> {{task.name}} <button ng-click="removeTask({{task.id}})">remove</button> </li> There is a function in the controller $scope.removeTask(taskID) . As far as I know Angular will first render the view and replace interpolated {{task.id}} with a number, and then, on click event, will evaluate ng-click string. In this case ng-click gets totally what is expected, ie: ng-click="removeTask(5)". However... it's not doing

AngularJS Button to reload state does not work

可紊 提交于 2019-12-25 14:14:19
问题 I want to have a button on the front end (AngularJS) that refreshes the changes made to the database. I have tried the following in the html: <button ng-click="reloadState" data-translate> Refresh Database </button> In the app.js file, I have this function in my controller: $scope.reloadState = function() { $state.go($state.current, {}, {reload: true}); } I have also tried: $scope.reloadState = function() { $state.reload(); }; and: $scope.reloadState = function() { window.location.reload(); }

Injecting HTML into the DOM destroys the AngularJS events

主宰稳场 提交于 2019-12-25 12:08:40
问题 I have included a third party script in my angularJS app, which appends some HTML to the body document.body.innerHTML += thirdPartyHTML; Whenever that is done it seems like my ng-click events won't fire. Is the HTML by the third party script appending the HTML in the wrong way, or should I somehow refresh AngularJS view on the DOM ($scope.$apply) ? Update : It seems like I can reproduce the error, with just calling document.body.innerHTML += ''; myself. It apparently hasn't anything to do

How to trigger ngClick programmatically

╄→尐↘猪︶ㄣ 提交于 2019-12-25 09:24:42
问题 I want to trigger ng-click of an element at runtime like: _ele.click(); OR _ele.trigger('click', function()); How can this be done? 回答1: The syntax is the following: function clickOnUpload() { $timeout(function() { angular.element('#myselector').triggerHandler('click'); }); }; // Using Angular Extend angular.extend($scope, { clickOnUpload: clickOnUpload }); // OR Using scope directly $scope.clickOnUpload = clickOnUpload; More info on Angular Extend way here. If you are using old versions of

Popover content not working with angularjs ng-click

China☆狼群 提交于 2019-12-25 02:38:38
问题 I have already read all the posts about this, but unfortunately none of them was helpful: jsfiddle and plunker links appear to be no longer working. What I am trying to do is to simply put a button inside the bootstrap pop-over which makes a call to a function inside the scope of the directive I've created. The problem is that using jquery to grab the content it does not work since the scope appear to be outside. Also trying to create the content inside the function it won't work because it