Skip to content

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

Open
jopss wants to merge 2 commits into
darylrowland:masterfrom
jopss:master
Open

Change to receive and select item by functions js.#117
jopss wants to merge 2 commits into
darylrowland:masterfrom
jopss:master

Conversation

@jopss

@jopss jopss commented Jan 21, 2016

Copy link
Copy Markdown

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