Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to receive and select item by functions js. #117

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jopss
Copy link

@jopss jopss commented Jan 21, 2016

Adding option to receive data from a function, and select an object also by a function. It can be used with Restangular, for example:

CONTROLLER:

angular.module("app.whatever")
        .controller("MyController", myController);

function myController($scope, MyService) {
        var vm = this;
        vm.init = init;
        vm.findRemoteObjects = findRemoteObjects;
        vm.selectItem = selectItem;

        function findRemoteObjects(filter) {
            MyService.findRemote(filter).then(function (result) {
                vm.listObjects = result;
            }, function (result) {
                console.log("error: "+result);
            });
        };

        function selectItem(item) {
                vm.selectedItem = item;
        }

        function init() {
                vm.selectedItem = null;
                vm.listObjects = [];
        }

        vm.init();
}

SERVICE RESTANGULAR

angular.module("app.whatever")
        .service("MyService", ["Restangular", function (Restangular) {
                        this.findRemote = function (autocompleteFilter) {
                                return Restangular.one("http://myapp/find").get({filter: autocompleteFilter});
                        };
                }
        ]);

COMPONENT

<angucomplete id="id_comp"
      placeholder="Hey..."
      pause="400"
      selectedaction="vm.selectItem"
      action="vm.findRemoteObjects"
      datafield="vm.listObjects"
      titlefield="attrtitle"
      descriptionfield="attrdesc"
      inputclass="form-control form-control-small"/>

jopss added 2 commits January 21, 2016 16:42
…lso by a function. It can be used with Restangular, for example.
…lso by a function. It can be used with Restangular, for example.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant