richard smith

richard smith

  • 1.4k
  • 285
  • 160.7k

Event Not Firing

Dec 28 2017 3:44 PM
My DoTheWork() event is not firing.  Can someone show me how I should re-write so the event fires?
 
[code]
$scope.matches = [];
$scope.relations = [];
$scope.getAnswer = function($event, choice) {
$scope.picked = choice.question;
$http({
method: "POST",
url: "/LSN/LSA",
dataType: 'json',
data: JSON.stringify(choice),
headers: {
"Content-Type": "application/json"
}
}).then(function(response) {
$scope.items = response.data;
$scope.isnum = response.data[0].isnumeric;
var parentEl = angular.element(document.body);
if ($scope.isnum) {
$mdDialog.show({
parent: parentEl,
scope: $scope,
preserveScope: true,
targetEvent: $event,
disableParentScroll: false,
template: '' +
'' +
'
' +
'

' + '' +

'' +
'' +
'clear' +
'' +
'
' +
'' +
'' +
'
' +
'' +
'

Use autocomplete to search for typical answers.

' +
'
'md-selected-item="ctrl.selectedItem" ' +
'md-search-text="ctrl.searchText" ' +
'md-items="item in items" ' +
'md-item-text="item.answer" ' +
'md-min-length="0" ' +
'placeholder="Click to see options" ' +
'md-autofocus> ' +
' ' +
'{{item.answer}} ' +
' ' +
'' +
'' +
'
' +
'' +
'' +
'Complete' +
'' +
'',
controller: DoTheWork,
controllerAs: 'ctrl'
});
}
function DoTheWork($scope, $mdDialog, $http, sharedData) {
$scope.clickAnswer = function(item) {
var idx = -1;
for (var itr = 0; itr < $scope.matches.length; itr++) {
if ($scope.matches[itr].answer == item.answer) {
idx = itr;
break;
}
}
if (idx > -1) {
$scope.matches.splice(idx, 1);
} else {
$scope.matches.push(item);
}
}
var self = this;
self.cancel = function($event) {
$mdDialog.cancel();
};
self.finish = function($event) {
$mdDialog.hide();
};
$scope.closeDialog = function() {
var sku = sharedData.getSkuItem();
$scope.relations = [];
for (var itr = 0; itr < $scope.matches.length; itr++) {
var relation = {};
relation.id = 0;
relation.s = s.IC;
relation.identifier = choice.identifier;
relation.answer = $scope.matches[itr].answer;
$scope.relations.push(relation);
};
$scope.matches = [];
$http({
method: "POST",
url: "/Lumbda/Rela",
dataType: 'json',
data: JSON.stringify($scope.relations),
}).then(function(response) {
$scope.status = response.data;
}, function(response) {
$scope.error = response.statusText;
alert('Error ' + response.statusText);
});
$mdDialog.hide();
}
}
}, function(response) {
$scope.items = [];
$scope.error = response.statusText;
alert('Error  ' + response.statusText);
});
[/code] 

Answers (1)