Ich entwickle eine angular-node.js-Anwendung als ein Cloud-Plugin für Jira, wo ich eine Schaltfläche habe, die beim Anklicken eine Post-Anfrage auslöst. Ich stehe vor einem seltsamen Problem, bei dem diese Postanforderung aufgerufen wird, wie oft die Schaltfläche geklickt wurde. Zum Beispiel, wenn ich zum ersten Mal auf die Schaltfläche klicke - Post-Anfrage wird einmal aufgerufen, wenn ich erneut klicke, ist das das zweite Mal, dass die Post-Anfrage zweimal ausgeführt wird und so weiter. Sobald ich die Seite aktualisiere, beginnt sie wieder bei Null. Hier ist der Code:Wie binde ich einmal pro ng-Klick?
Controller-Code:
$scope.addActor = function(){
AP.require('dialog', function(dialog){
dialog.create({
key: 'actor-content',
width: '40%',
height: '30%',
chrome: true,
});
});
AP.require('events', function(events){
events.on('customEvent', function(){
console.log(arguments[0]);
var data = {
productName: $scope.productName,
checked: false,
actor: arguments[0]
};
$http.post('/addActor', data)
.success(function(data){
$scope.actors = [];
for (var actor in data){
console.log(data[actor].checked)
console.log(data[actor].actor)
$scope.actors.push({
checked : data[actor].checked,
id : data[actor].actor
});
}
AP.require("messages", function(messages){
//create a message
var message = messages.success('','Actor added');
setTimeout(function(){
messages.clear(message);
}, 2000);
});
/*$scope.formData = {};*/
}).error(function(data){
AP.require("messages", function(messages){
//create a message
var message = messages.error('','Error in Adding Actor');
setTimeout(function(){
messages.clear(message);
}, 2000);
});
});
});
});
};
dialogActor.hbs
<body style="background:white">
<div class="aui-dialog2-content">
<script>
$(document).one('click', function(e) {
// initialization here
AP.require('dialog', function(dialog) {
dialog.getButton('submit').bind(function() {
AP.require('events', function(events){
var actor = $('#actor').val();
events.emit('customEvent', actor);
});
dialog.close();
});
dialog.getButton('cancel').bind(function() {
dialog.close();
});
});
});
</script>
<form class="aui" action="#" name="jiraform" id="actorform">
<div class="content">
<div class="field-group">
<label for="summary">Actor<span class="aui-icon icon-required">Required</span></label>
<input type="text" value="" name="actor" id="actor" class="text long-field" data-aui-validation-field data-aui-validation-required="required" required>
<span class="actorError" style="color: #880000"></span>
</div>
</div>
</form>
</div>
</body>
Wie identifizieren Sie die Anfrage mehrmals, von der Netzwerk-Registerkarte oder von der console.log() ??? – Saubar