Question

Thanks to SOF for solving my last issue in angularjs and autocomplete. Angularjs with jquery auto complete not working

Now, I have an issue of same type in ng-repeat...

In View

<tr data-ng-repeat="item in pagedItems">
                    <td title={{item.name}}>{{item.name}}</td>
                    <td> <input type=text auto-complete ng-model="item.upload_status">
                    Upload status: {{item.upload_status}}</td>
                    <td title={{item.lat}}>{{item.lat}}</td>
                    <td title={{item.lon}}>{{item.lon}}</td>
                </tr>

In Directive

myapp.directive('autoComplete', function(autoCompleteDataService) {
return {
    restrict: 'A',
    link: function(scope, elem, attr, ctrl) {

        elem.autocomplete({

            source: autoCompleteDataService.getSource(), 

            select: function( event, ui ) {
                scope.$apply(function() { this.item.upload_status = ui.item.value; });
            },

            change: function (event, ui) {
                if (ui.item === null) {
                    scope.$apply(function() { scope.foo = null });
                }
            },
            minLength: 2
        });
    }
};

});

It is giving error as,

TypeError: Cannot set property 'upload_status' of undefined

Any idea to update upload_status is appreciated..

Was it helpful?

Solution

this.item.upload_status should be scope.item.upload_status

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top