代码如下:抛异常 Error: [$injector:unpr]
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<script type="text/javascript" src="js/angular.min.1.3.6.js"></script>
</head>
<body ng-app='myapp1'>
<cus></cus>
</body>
<script type="text/javascript">
var app = angular.module('myapp1', []);
//抛这个异常,问题在这段段代码:这里函数的参数多传入了$scope,去掉后,异常解决
//跑这个异常说明注入内容有问题,遇到类似异常,检查注入内容是否正确!!!
app.directive("cus",function($scope){
return function(scope,element,attrs){
console.log('返回element=='+element);
}
});
</script>
</html>
本文通过一个具体的Angular应用实例,探讨了在使用Angular自定义指令时出现的注入错误问题。详细分析了错误产生的原因,并提供了如何避免此类错误的有效方法。

479

被折叠的 条评论
为什么被折叠?



