为了账号安全,请及时绑定邮箱和手机立即绑定

关于angularJs ngRepeat指令的作用域和element问题

关于angularJs ngRepeat指令的作用域和element问题

qq_Microuncle_0 2016-10-07 21:45:51
<!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试试看看,是不是就指向了相应的标签。

查看完整回答
反对 回复 2016-10-22
  • 1 回答
  • 0 关注
  • 1446 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信