<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>navbar</title>
<link rel="stylesheet" href="../lib/bootstrap/dist/css/bootstrap.min.css">
<script src="../lib/angular/angular.js"></script>
</head>
<body ng-app="myapp" ng-controller="ctrl">
<hello menu="navs"></hello>
</body>
<script>
var app=angular.module("myapp",[]);
app.controller("ctrl",function ($scope) {
$scope.navs=[
{title:"this is first title",items:["one","two","three"]},
{title:"this is second title",items:["one","two","three"]},
{title:"this is third title",items:["one","two","three"]}
]
})
app.directive("hello",function () {
return {
restrict:"EA",
replace:true,
scope:{
text:"=menu",
},
template:"<div ng-repeat='i in text'><div>{{i.title}}</div><div ng-show='showme' ng-init='showme=true' ng-repeat='item in i.items'>{{item}}</div></div>",
link:function (scope, ele, attr, ctrl) {
// scope.showme=true;
console.log(scope,ele,attr,ctrl);
}
}
})
</script>
</html>直接上代码,在这个代码中ele没有指向,如何解释?
1 回答
李晓健
TA贡献1036条经验 获得超461个赞
应该是 replace:true, 新生成的标签把应该指向的标签给替换掉了,所以就没有相应的标签指向了,就只向上ng生成的一行注释。你可以把true改成false试试看看,是不是就指向了相应的标签。
- 1 回答
- 0 关注
- 1474 浏览
添加回答
举报
0/150
提交
取消