Javascript 未定义$compile 使用angular.elements动态创建元素-AngularJS
我需要使用angular创建一个指令元素。但是在使用angular.element时没有运气。以$compile未定义错误结束。非常感谢您的帮助 text-field-personal.htmlJavascript 未定义$compile 使用angular.elements动态创建元素-AngularJS,javascript,html,angularjs,dom,Javascript,Html,Angularjs,Dom,我需要使用angular创建一个指令元素。但是在使用angular.element时没有运气。以$compile未定义错误结束。非常感谢您的帮助 text-field-personal.html <input ng-focus="setIndex(field.id);field.focus()" id="{{field.id}}" type="{{field.type}}" name="{{field.id
<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>
在我的index.html中,我将使用如下指令
<text-field-personal> </text-field-personal>
但是我想在javascript DOM元素中创建同样的元素。像下面这样尝试,但没有运气
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);
var divv=document.createElement(“div”);
var newDirective=angular.element(“”);
divv.append(新指令);
$compile(newDirective)($scope);
$compile未定义,因为它未注入指令:
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) {
未定义$compile,因为未将其注入指令:
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) {
“没有运气”不是一个有用的问题描述<代码>$compile未定义,因为未将其注入指令。“不走运”不是一个有用的问题描述<代码>$compile未定义,因为它未注入指令。