Ionic Popup $timeout issue with working Codepen

Hey Guys, I need your help.
My Problem:
The User enters Data into an Input Field if the Data is not correct I call IonicPopup close the soft Keyboard and show a customized alert Window, after the User clicks Ok, I want to mark the text of the inputfield he entered his data. Everything works fine, except the select / setSelectionRange (tried both) isnt working, and i get the following Error:

Here is a working Codepen where it somehow works !!!


TypeError: undefined is not a function
    at file:///data/data/com.bmtricon.Datakey/files/12590FAA-5EDD-4B12-856D-F52A0A1599F2/js/services.js:400:74
    at file:///data/data/com.bmtricon.Datakey/files/12590FAA-5EDD-4B12-856D-F52A0A1599F2/lib/ionic/js/ionic.bundle.js:24142:28
    at completeOutstandingRequest (file:///data/data/com.bmtricon.Datakey/files/12590FAA-5EDD-4B12-856D-F52A0A1599F2/lib/ionic/js/ionic.bundle.js:12824:10)
    at file:///data/data/com.bmtricon.Datakey/files/12590FAA-5EDD-4B12-856D-F52A0A1599F2/lib/ionic/js/ionic.bundle.js:13204:7

Here is my Code:


.factory('NotificationService', function ($ionicPopup, $timeout) {
    return {
        showAlert: function (title, msg, rep1, rep2, btn, iptField, bcnt, vibs) {
            if (rep1 != null && rep2 != null) {
                var tmpMsga = msg; 
                var tmpMsgb = msg.replace("'{0}'", rep1);
                var tmpMsgc = tmpMsgb.replace("'{1}'", rep2);
            } else if (rep1 != null && rep2 == null) {
                var tmpMsga = msg;
                var tmpMsgc = tmpMsga.replace("'{0}'", rep1);
            } else if (rep1 == null && rep2 == null) {
                var tmpMsgc = msg;
            var alertPopup = $ionicPopup.alert({
                title: title,
                template: tmpMsgc,
                cssClass: 'test',
                buttons: [{
                    text: btn,
                    type: 'button-stable popup-ok'
            alertPopup.then(function () {
                $timeout(function () {

//LINE of Error

angular.element(document.querySelector(iptField))[0].setSelectionRange(0, 6);
                    }, 500);
            showConfirm: function (title, msg, btnCancel, btnOk, bcnt, vibs) {
                var confirmPopup = $ionicPopup.confirm({
                    title: title,
                    template: msg,
                    buttons: [
                            text: btnCancel,
                            type: 'button-confirm'
                            text: btnOk,
                            type: 'button-confirm'    


NotificationService.showAlert($scope.lang.MsgTitelFehler, $scope.lang.MsgArtikelExistiertNicht, article, null, $scope.lang.btnOkML, '#f_4', 0, 200);


<label class="item item-input">
                    <span class="input-label">{{lang.lblArtikelNrLangML}}</span>
                    <input type="text" id="f_4" name="articlenummer" ng-keyup="$event.keyCode == 13 ? keypressEvent($event, 2) : null" ng-model="info.articlenummer" ng-change="updateArticle(info.articlenummer)" required>

The Crazy thing is on my First Formular this works without any Problems, on The 2nd it doesnt.
Please Help me

Solved the Problem it seems i had to change the selection of the inputfields