{"action":"created","issue":{"url":"https://api.github.com/repos/mgcrea/angular-strap/issues/1448","labels_url":"https://api.github.com/repos/mgcrea/angular-strap/issues/1448/labels{/name}","comments_url":"https://api.github.com/repos/mgcrea/angular-strap/issues/1448/comments","events_url":"https://api.github.com/repos/mgcrea/angular-strap/issues/1448/events","html_url":"https://github.com/mgcrea/angular-strap/issues/1448","id":55028706,"number":1448,"title":"Typeahead Moves to End of The Field When Typing","user":{"login":"kkirsche","id":947110,"avatar_url":"https://avatars.githubusercontent.com/u/947110?v=3","gravatar_id":"","url":"https://api.github.com/users/kkirsche","html_url":"https://github.com/kkirsche","followers_url":"https://api.github.com/users/kkirsche/followers","following_url":"https://api.github.com/users/kkirsche/following{/other_user}","gists_url":"https://api.github.com/users/kkirsche/gists{/gist_id}","starred_url":"https://api.github.com/users/kkirsche/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kkirsche/subscriptions","organizations_url":"https://api.github.com/users/kkirsche/orgs","repos_url":"https://api.github.com/users/kkirsche/repos","events_url":"https://api.github.com/users/kkirsche/events{/privacy}","received_events_url":"https://api.github.com/users/kkirsche/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/mgcrea/angular-strap/labels/directive-typeahead","name":"directive-typeahead","color":"444444"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-01-21T14:55:25Z","updated_at":"2015-02-03T19:11:56Z","closed_at":null,"body":"The typeahead module doesn't respect where you are in an input and instead pulls you to the end of the input.\r\n\r\nFor example, if you type in the sample \"rgi\" and realize you you forgot the beginning, you can't jump to the first part of the input and add \"Vi\" to get \"Virgi\" as you type \"Virginia\"\r\n\r\nExample:\r\nhttps://www.youtube.com/watch?v=L7YdT8SSWm0\r\n\r\n![typeahead](https://cloud.githubusercontent.com/assets/947110/5838195/9da21dfe-a153-11e4-8eb1-596ddad1db48.gif)\r\n \r\nAfter further research this seems to be caused by this line in the typeahead module:\r\n```javascript\r\nelement.val(selected ? selected.toString().replace(/<(?:.|\\n)*?>/gm, '').trim() : '');\r\n```\r\n\r\nIf we don't call `controller.$render();` in this block at the end this fixes this issue:\r\n\r\n```javascript\r\n// Watch model for changes\r\n        scope.$watch(attr.ngModel, function(newValue, oldValue) {\r\n          // console.warn('$watch', element.attr('ng-model'), newValue);\r\n          scope.$modelValue = newValue; // Publish modelValue on scope for custom templates\r\n          parsedOptions.valuesFn(scope, controller)\r\n          .then(function(values) {\r\n            // Prevent input with no future prospect if selectMode is truthy\r\n            // @TODO test selectMode\r\n            if(options.selectMode && !values.length && newValue.length > 0) {\r\n              controller.$setViewValue(controller.$viewValue.substring(0, controller.$viewValue.length - 1));\r\n              return;\r\n            }\r\n            if(values.length > limit) values = values.slice(0, limit);\r\n            var isVisible = typeahead.$isVisible();\r\n            isVisible && typeahead.update(values);\r\n            // Do not re-queue an update if a correct value has been selected\r\n            if(values.length === 1 && values[0].value === newValue) return;\r\n            !isVisible && typeahead.update(values);\r\n            // Queue a new rendering that will leverage collection loading\r\n            controller.$render();\r\n          });\r\n        });\r\n```"},"comment":{"url":"https://api.github.com/repos/mgcrea/angular-strap/issues/comments/72714128","html_url":"https://github.com/mgcrea/angular-strap/issues/1448#issuecomment-72714128","issue_url":"https://api.github.com/repos/mgcrea/angular-strap/issues/1448","id":72714128,"user":{"login":"kkirsche","id":947110,"avatar_url":"https://avatars.githubusercontent.com/u/947110?v=3","gravatar_id":"","url":"https://api.github.com/users/kkirsche","html_url":"https://github.com/kkirsche","followers_url":"https://api.github.com/users/kkirsche/followers","following_url":"https://api.github.com/users/kkirsche/following{/other_user}","gists_url":"https://api.github.com/users/kkirsche/gists{/gist_id}","starred_url":"https://api.github.com/users/kkirsche/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kkirsche/subscriptions","organizations_url":"https://api.github.com/users/kkirsche/orgs","repos_url":"https://api.github.com/users/kkirsche/repos","events_url":"https://api.github.com/users/kkirsche/events{/privacy}","received_events_url":"https://api.github.com/users/kkirsche/received_events","type":"User","site_admin":false},"created_at":"2015-02-03T19:11:56Z","updated_at":"2015-02-03T19:11:56Z","body":"Interesting. Thanks for sharing that info @bstruthers "}}