$编译显示未捕获类型错误:未定义不是一个函数 [英] $compile showing uncaught TypeError: undefined is not a function
本文介绍了$编译显示未捕获类型错误:未定义不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用下面的code。要针对特定元素,并附加< DIV>
里面的那个,但得到未捕获类型错误:未定义不是 $编译(newDirective)的函数( $范围内);
$ scope.grid =功能(targetElement)
{
的console.log(目标元素,targetElement)
VAR newDirective = angular.element(< DIV的风格=高度:200像素'>
示例code
< / DIV>中);
targetElement.append(newDirective);
$编译(newDirective)($范围内);
}
解决方案
试试这个code。
$ scope.grid =功能(targetElement)
{
变量$ DIV = $(< DIV的风格=高度:200像素'>样品code< / DIV>中);
$(targetElement).append($ DIV); angular.element(targetElement).injector()调用(函数($编译){
VAR范围= angular.element($ DIV).scope();
$编译($ DIV)(范围);
});
}
I am using the following code. To target the particular element and append a <div>
inside that but getting uncaught typeerror: undefined is not a function for $compile(newDirective)($scope);
$scope.grid= function (targetElement)
{
console.log("target element",targetElement)
var newDirective = angular.element("<div style='height:200px' >
Sample code
</div>");
targetElement.append(newDirective);
$compile(newDirective)($scope);
}
解决方案
Try this code.
$scope.grid= function (targetElement)
{
var $div = $("<div style='height:200px' > Sample code </div>");
$(targetElement).append($div);
angular.element(targetElement).injector().invoke(function($compile) {
var scope = angular.element($div).scope();
$compile($div)(scope);
});
}
这篇关于$编译显示未捕获类型错误:未定义不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文