$compile is not defined












0















Dynamic creation of elements using angular.elements - AngularJS



I need to create a directive element using angular. But no luck in using angular.element . Ended up with $compile is not defined error. Any help is much appreciated.



text-field-personal.html



<input ng-focus="setIndex(field.id);field.focus()" id="{{field.id}}"
type="{{field.type}}" name="{{field.id}}" ng-model="field.text"
class="login_input_personal {{field.selectedClass}} {{enabledCursor}} {{field.text == '' ? 'blank' : ''}}"
ng-mouseup="clearSelected(field.id);"
ng-mousedown="startDrag(field.id);" />
<div class="placeholder" ng-show="field.text == ''"
{{interfaceLabels[field.defaultText]}}
</div>
<div class="placeholder" ng-show="field.text == ''"></div>
<a class="clear-textfield" ng-click="clearTextField();"
ng-if="emailTextfieldClearButton"
ng-show="field.text != '' && field.selectedClass != ''">
</a>


And this is my



textField.js



angular
.module("textBoxUi")
.directive("textFieldPersonal", ['$rootScope', function($rootScope) {
return {
restrict : 'E',
templateUrl : 'components/text-field-personal.html',
scope : {
field : "="
},

link : function (scope, element, attr) {
scope.interfaceLabels = scope.$parent.interfaceLabels;
scope.emailTextfieldClearButton = $rootScope.emailTextfieldClearButton;
scope.enabledCursor = $rootScope.enabledCursor;
scope.setIndex= function(id){
$rootScope.textFieldIndex = document.getElementById(id).selectionStart;
};
scope.startDrag = function(e){
var e = window.event;
scope.startDragX = e.pageX;
e = null;
};
scope.clearSelected = function(id){
var e = window.event;
scope.stopDragX = e.pageX;
if(scope.stopDragX > scope.startDragX){
document.getElementById(id).setSelectionRange(document.getElementById(id).selectionEnd, document.getElementById(id).selectionEnd);
$rootScope.textFieldIndex = document.getElementById(id).selectionEnd;
}else {
document.getElementById(id).setSelectionRange(document.getElementById(id).selectionStart, document.getElementById(id).selectionStart);
$rootScope.textFieldIndex = document.getElementById(id).selectionStart;
}
e = null;
};
scope.clearTextField = function(){
$rootScope.targetField.text ="";
$rootScope.hideEmailExtensionTop();
document.getElementById($rootScope.targetField.id).value = $rootScope.targetField.text;
if(typeof(scope.field.callback) === "function"){
scope.field.callback();
}
};

scope.enabledCursorWatch = $rootScope.$watch('enabledCursor', function(){
scope.enabledCursor = $rootScope.enabledCursor;
});

}
}
}]);


In my index.html i would use my directive like the following



<text-field-personal> </text-field-personal>


But i would like to create the same in javascript DOM elements. Tried like the following but no luck.



  var divv = document.createElement("div");
var newDirective = angular.element("<input ng-focus='setIndex(field.id);field.focus()' id='{{field.id}}' type='{{field.type}}' name='{{field.id}}' ng-model='field.text' class='login_input_new {{field.selectedClass}} {{enabledCursor}} {{field.text == '' ? 'blank' : ''}}' ng-mouseup='clearSelected(field.id);' ng-mousedown='startDrag(field.id);'/><a class='clear-textfield' ng-click='clearTextField();' ng-if='emailTextfieldClearButton' ng-show='field.text != '' && field.selectedClass != '''></a>");
divv.append(newDirective);
$compile(newDirective)($scope);









share|improve this question




















  • 1





    "no luck" is not a helpful problem description. $compile is not defined because it is not injected into the directive.

    – georgeawg
    Nov 25 '18 at 15:22


















0















Dynamic creation of elements using angular.elements - AngularJS



I need to create a directive element using angular. But no luck in using angular.element . Ended up with $compile is not defined error. Any help is much appreciated.



text-field-personal.html



<input ng-focus="setIndex(field.id);field.focus()" id="{{field.id}}"
type="{{field.type}}" name="{{field.id}}" ng-model="field.text"
class="login_input_personal {{field.selectedClass}} {{enabledCursor}} {{field.text == '' ? 'blank' : ''}}"
ng-mouseup="clearSelected(field.id);"
ng-mousedown="startDrag(field.id);" />
<div class="placeholder" ng-show="field.text == ''"
{{interfaceLabels[field.defaultText]}}
</div>
<div class="placeholder" ng-show="field.text == ''"></div>
<a class="clear-textfield" ng-click="clearTextField();"
ng-if="emailTextfieldClearButton"
ng-show="field.text != '' && field.selectedClass != ''">
</a>


And this is my



textField.js



angular
.module("textBoxUi")
.directive("textFieldPersonal", ['$rootScope', function($rootScope) {
return {
restrict : 'E',
templateUrl : 'components/text-field-personal.html',
scope : {
field : "="
},

link : function (scope, element, attr) {
scope.interfaceLabels = scope.$parent.interfaceLabels;
scope.emailTextfieldClearButton = $rootScope.emailTextfieldClearButton;
scope.enabledCursor = $rootScope.enabledCursor;
scope.setIndex= function(id){
$rootScope.textFieldIndex = document.getElementById(id).selectionStart;
};
scope.startDrag = function(e){
var e = window.event;
scope.startDragX = e.pageX;
e = null;
};
scope.clearSelected = function(id){
var e = window.event;
scope.stopDragX = e.pageX;
if(scope.stopDragX > scope.startDragX){
document.getElementById(id).setSelectionRange(document.getElementById(id).selectionEnd, document.getElementById(id).selectionEnd);
$rootScope.textFieldIndex = document.getElementById(id).selectionEnd;
}else {
document.getElementById(id).setSelectionRange(document.getElementById(id).selectionStart, document.getElementById(id).selectionStart);
$rootScope.textFieldIndex = document.getElementById(id).selectionStart;
}
e = null;
};
scope.clearTextField = function(){
$rootScope.targetField.text ="";
$rootScope.hideEmailExtensionTop();
document.getElementById($rootScope.targetField.id).value = $rootScope.targetField.text;
if(typeof(scope.field.callback) === "function"){
scope.field.callback();
}
};

scope.enabledCursorWatch = $rootScope.$watch('enabledCursor', function(){
scope.enabledCursor = $rootScope.enabledCursor;
});

}
}
}]);


In my index.html i would use my directive like the following



<text-field-personal> </text-field-personal>


But i would like to create the same in javascript DOM elements. Tried like the following but no luck.



  var divv = document.createElement("div");
var newDirective = angular.element("<input ng-focus='setIndex(field.id);field.focus()' id='{{field.id}}' type='{{field.type}}' name='{{field.id}}' ng-model='field.text' class='login_input_new {{field.selectedClass}} {{enabledCursor}} {{field.text == '' ? 'blank' : ''}}' ng-mouseup='clearSelected(field.id);' ng-mousedown='startDrag(field.id);'/><a class='clear-textfield' ng-click='clearTextField();' ng-if='emailTextfieldClearButton' ng-show='field.text != '' && field.selectedClass != '''></a>");
divv.append(newDirective);
$compile(newDirective)($scope);









share|improve this question




















  • 1





    "no luck" is not a helpful problem description. $compile is not defined because it is not injected into the directive.

    – georgeawg
    Nov 25 '18 at 15:22
















0












0








0








Dynamic creation of elements using angular.elements - AngularJS



I need to create a directive element using angular. But no luck in using angular.element . Ended up with $compile is not defined error. Any help is much appreciated.



text-field-personal.html



<input ng-focus="setIndex(field.id);field.focus()" id="{{field.id}}"
type="{{field.type}}" name="{{field.id}}" ng-model="field.text"
class="login_input_personal {{field.selectedClass}} {{enabledCursor}} {{field.text == '' ? 'blank' : ''}}"
ng-mouseup="clearSelected(field.id);"
ng-mousedown="startDrag(field.id);" />
<div class="placeholder" ng-show="field.text == ''"
{{interfaceLabels[field.defaultText]}}
</div>
<div class="placeholder" ng-show="field.text == ''"></div>
<a class="clear-textfield" ng-click="clearTextField();"
ng-if="emailTextfieldClearButton"
ng-show="field.text != '' && field.selectedClass != ''">
</a>


And this is my



textField.js



angular
.module("textBoxUi")
.directive("textFieldPersonal", ['$rootScope', function($rootScope) {
return {
restrict : 'E',
templateUrl : 'components/text-field-personal.html',
scope : {
field : "="
},

link : function (scope, element, attr) {
scope.interfaceLabels = scope.$parent.interfaceLabels;
scope.emailTextfieldClearButton = $rootScope.emailTextfieldClearButton;
scope.enabledCursor = $rootScope.enabledCursor;
scope.setIndex= function(id){
$rootScope.textFieldIndex = document.getElementById(id).selectionStart;
};
scope.startDrag = function(e){
var e = window.event;
scope.startDragX = e.pageX;
e = null;
};
scope.clearSelected = function(id){
var e = window.event;
scope.stopDragX = e.pageX;
if(scope.stopDragX > scope.startDragX){
document.getElementById(id).setSelectionRange(document.getElementById(id).selectionEnd, document.getElementById(id).selectionEnd);
$rootScope.textFieldIndex = document.getElementById(id).selectionEnd;
}else {
document.getElementById(id).setSelectionRange(document.getElementById(id).selectionStart, document.getElementById(id).selectionStart);
$rootScope.textFieldIndex = document.getElementById(id).selectionStart;
}
e = null;
};
scope.clearTextField = function(){
$rootScope.targetField.text ="";
$rootScope.hideEmailExtensionTop();
document.getElementById($rootScope.targetField.id).value = $rootScope.targetField.text;
if(typeof(scope.field.callback) === "function"){
scope.field.callback();
}
};

scope.enabledCursorWatch = $rootScope.$watch('enabledCursor', function(){
scope.enabledCursor = $rootScope.enabledCursor;
});

}
}
}]);


In my index.html i would use my directive like the following



<text-field-personal> </text-field-personal>


But i would like to create the same in javascript DOM elements. Tried like the following but no luck.



  var divv = document.createElement("div");
var newDirective = angular.element("<input ng-focus='setIndex(field.id);field.focus()' id='{{field.id}}' type='{{field.type}}' name='{{field.id}}' ng-model='field.text' class='login_input_new {{field.selectedClass}} {{enabledCursor}} {{field.text == '' ? 'blank' : ''}}' ng-mouseup='clearSelected(field.id);' ng-mousedown='startDrag(field.id);'/><a class='clear-textfield' ng-click='clearTextField();' ng-if='emailTextfieldClearButton' ng-show='field.text != '' && field.selectedClass != '''></a>");
divv.append(newDirective);
$compile(newDirective)($scope);









share|improve this question
















Dynamic creation of elements using angular.elements - AngularJS



I need to create a directive element using angular. But no luck in using angular.element . Ended up with $compile is not defined error. Any help is much appreciated.



text-field-personal.html



<input ng-focus="setIndex(field.id);field.focus()" id="{{field.id}}"
type="{{field.type}}" name="{{field.id}}" ng-model="field.text"
class="login_input_personal {{field.selectedClass}} {{enabledCursor}} {{field.text == '' ? 'blank' : ''}}"
ng-mouseup="clearSelected(field.id);"
ng-mousedown="startDrag(field.id);" />
<div class="placeholder" ng-show="field.text == ''"
{{interfaceLabels[field.defaultText]}}
</div>
<div class="placeholder" ng-show="field.text == ''"></div>
<a class="clear-textfield" ng-click="clearTextField();"
ng-if="emailTextfieldClearButton"
ng-show="field.text != '' && field.selectedClass != ''">
</a>


And this is my



textField.js



angular
.module("textBoxUi")
.directive("textFieldPersonal", ['$rootScope', function($rootScope) {
return {
restrict : 'E',
templateUrl : 'components/text-field-personal.html',
scope : {
field : "="
},

link : function (scope, element, attr) {
scope.interfaceLabels = scope.$parent.interfaceLabels;
scope.emailTextfieldClearButton = $rootScope.emailTextfieldClearButton;
scope.enabledCursor = $rootScope.enabledCursor;
scope.setIndex= function(id){
$rootScope.textFieldIndex = document.getElementById(id).selectionStart;
};
scope.startDrag = function(e){
var e = window.event;
scope.startDragX = e.pageX;
e = null;
};
scope.clearSelected = function(id){
var e = window.event;
scope.stopDragX = e.pageX;
if(scope.stopDragX > scope.startDragX){
document.getElementById(id).setSelectionRange(document.getElementById(id).selectionEnd, document.getElementById(id).selectionEnd);
$rootScope.textFieldIndex = document.getElementById(id).selectionEnd;
}else {
document.getElementById(id).setSelectionRange(document.getElementById(id).selectionStart, document.getElementById(id).selectionStart);
$rootScope.textFieldIndex = document.getElementById(id).selectionStart;
}
e = null;
};
scope.clearTextField = function(){
$rootScope.targetField.text ="";
$rootScope.hideEmailExtensionTop();
document.getElementById($rootScope.targetField.id).value = $rootScope.targetField.text;
if(typeof(scope.field.callback) === "function"){
scope.field.callback();
}
};

scope.enabledCursorWatch = $rootScope.$watch('enabledCursor', function(){
scope.enabledCursor = $rootScope.enabledCursor;
});

}
}
}]);


In my index.html i would use my directive like the following



<text-field-personal> </text-field-personal>


But i would like to create the same in javascript DOM elements. Tried like the following but no luck.



  var divv = document.createElement("div");
var newDirective = angular.element("<input ng-focus='setIndex(field.id);field.focus()' id='{{field.id}}' type='{{field.type}}' name='{{field.id}}' ng-model='field.text' class='login_input_new {{field.selectedClass}} {{enabledCursor}} {{field.text == '' ? 'blank' : ''}}' ng-mouseup='clearSelected(field.id);' ng-mousedown='startDrag(field.id);'/><a class='clear-textfield' ng-click='clearTextField();' ng-if='emailTextfieldClearButton' ng-show='field.text != '' && field.selectedClass != '''></a>");
divv.append(newDirective);
$compile(newDirective)($scope);






javascript html angularjs dom






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 15:27









georgeawg

33.6k105168




33.6k105168










asked Nov 25 '18 at 11:35









MishtyMishty

437




437








  • 1





    "no luck" is not a helpful problem description. $compile is not defined because it is not injected into the directive.

    – georgeawg
    Nov 25 '18 at 15:22
















  • 1





    "no luck" is not a helpful problem description. $compile is not defined because it is not injected into the directive.

    – georgeawg
    Nov 25 '18 at 15:22










1




1





"no luck" is not a helpful problem description. $compile is not defined because it is not injected into the directive.

– georgeawg
Nov 25 '18 at 15:22







"no luck" is not a helpful problem description. $compile is not defined because it is not injected into the directive.

– georgeawg
Nov 25 '18 at 15:22














1 Answer
1






active

oldest

votes


















2














$compile is not defined because it is not injected into the directive:



angular
.module("textBoxUi")
̶.̶d̶i̶r̶e̶c̶t̶i̶v̶e̶(̶"̶t̶e̶x̶t̶F̶i̶e̶l̶d̶P̶e̶r̶s̶o̶n̶a̶l̶"̶,̶ ̶[̶'̶$̶r̶o̶o̶t̶S̶c̶o̶p̶e̶'̶,̶ ̶f̶u̶n̶c̶t̶i̶o̶n̶(̶$̶r̶o̶o̶t̶S̶c̶o̶p̶e̶)̶ ̶{̶
.directive("textFieldPersonal", function($rootScope, $compile) {





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467026%2fcompile-is-not-defined%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    $compile is not defined because it is not injected into the directive:



    angular
    .module("textBoxUi")
    ̶.̶d̶i̶r̶e̶c̶t̶i̶v̶e̶(̶"̶t̶e̶x̶t̶F̶i̶e̶l̶d̶P̶e̶r̶s̶o̶n̶a̶l̶"̶,̶ ̶[̶'̶$̶r̶o̶o̶t̶S̶c̶o̶p̶e̶'̶,̶ ̶f̶u̶n̶c̶t̶i̶o̶n̶(̶$̶r̶o̶o̶t̶S̶c̶o̶p̶e̶)̶ ̶{̶
    .directive("textFieldPersonal", function($rootScope, $compile) {





    share|improve this answer




























      2














      $compile is not defined because it is not injected into the directive:



      angular
      .module("textBoxUi")
      ̶.̶d̶i̶r̶e̶c̶t̶i̶v̶e̶(̶"̶t̶e̶x̶t̶F̶i̶e̶l̶d̶P̶e̶r̶s̶o̶n̶a̶l̶"̶,̶ ̶[̶'̶$̶r̶o̶o̶t̶S̶c̶o̶p̶e̶'̶,̶ ̶f̶u̶n̶c̶t̶i̶o̶n̶(̶$̶r̶o̶o̶t̶S̶c̶o̶p̶e̶)̶ ̶{̶
      .directive("textFieldPersonal", function($rootScope, $compile) {





      share|improve this answer


























        2












        2








        2







        $compile is not defined because it is not injected into the directive:



        angular
        .module("textBoxUi")
        ̶.̶d̶i̶r̶e̶c̶t̶i̶v̶e̶(̶"̶t̶e̶x̶t̶F̶i̶e̶l̶d̶P̶e̶r̶s̶o̶n̶a̶l̶"̶,̶ ̶[̶'̶$̶r̶o̶o̶t̶S̶c̶o̶p̶e̶'̶,̶ ̶f̶u̶n̶c̶t̶i̶o̶n̶(̶$̶r̶o̶o̶t̶S̶c̶o̶p̶e̶)̶ ̶{̶
        .directive("textFieldPersonal", function($rootScope, $compile) {





        share|improve this answer













        $compile is not defined because it is not injected into the directive:



        angular
        .module("textBoxUi")
        ̶.̶d̶i̶r̶e̶c̶t̶i̶v̶e̶(̶"̶t̶e̶x̶t̶F̶i̶e̶l̶d̶P̶e̶r̶s̶o̶n̶a̶l̶"̶,̶ ̶[̶'̶$̶r̶o̶o̶t̶S̶c̶o̶p̶e̶'̶,̶ ̶f̶u̶n̶c̶t̶i̶o̶n̶(̶$̶r̶o̶o̶t̶S̶c̶o̶p̶e̶)̶ ̶{̶
        .directive("textFieldPersonal", function($rootScope, $compile) {






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 25 '18 at 15:30









        georgeawggeorgeawg

        33.6k105168




        33.6k105168
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467026%2fcompile-is-not-defined%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'