0

i am using ng-options to iterate some data in angularjs and when selecting value i want a selected Object , For that i have created directive..

return {
    require: 'ngModel',
    restrict  : 'A',
    link: function(scope, element, attrs, ctrl) {
        $(element).combobox({
            source: scope[attrs.reportitems],
            select: function(event, ui) {
                $timeout(function() {
                        if(attrs.reportitems=="zoneList"){
                            if(ui.item.attributes.value.value != "0") {
                                scope["update"](ui.item.attributes.value.value);
                            }
                        }
                }, 0);
            }
        });
    },
}

This will call update method in controller and it will pass the index position of data array but i want the object itself instead of index. or somehow trigger ng-change method in UI.so that i can have an Object in update Method in controller. please check this Plunker for whole Code..Link

Can anyone please help ?

1 Answer 1

1

As far as I can tell, the entire object is being passed through inside of an array when an item is selected. You just need res[0] to get access to the object. From there you have the id, tableName, and toolTip properties available. Alternatively, you could just assign ng-change=update(selected[0]) to get the object.

I'm curious as to why you define $scope.selected = [] then assign $scope.selected = res

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.