0

我有这个代码http://plnkr.co/edit/kiH0Ge?p=preview

<!doctype html>
<html ng-app="plunker" >
<head>
  <meta charset="utf-8">
  <title>AngularJS Plunker</title>
  <link rel="stylesheet" href="style.css">
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.js"></script>
  <script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
  <choice-tree ng-model="myTree" children="true"></choice-tree>
  <hr />
  $scope.myTree = {{myTree | json}}
</body>
</html>

我添加了参数 checkChildren

<choice-tree ng-model="myTree" checkChildren="true"></choice-tree>

然后在检查指令中我想有条件地运行函数

if(scope.checkChildren === 'true') 
   checkChildren(choice);

但它不起作用。

我知道有孤立的范围,但是如何构建树。

4

2 回答 2

0

如果我的理解是正确的,我认为这是一个简单的错字。稍作修改,它似乎正在工作: http: //plnkr.co/edit/BJqsl3

你想检查布尔值,例如scope.checkChildren === true 不反对'true'

[编辑] 看来我没有正确理解规范

如果我删除if上面指出的语句并调用 checkChildren(),它会起作用。这是你的意图吗?Plunk 会相应更新。

于 2012-09-20T09:02:17.960 回答
0

现在一切正常http://plnkr.co/edit/5lLGIQ?p=preview

我刚把孩子改成带孩子的,这(关键)

$compile('<choice-tree ng-model="choice.children" children="{{children}}"></choice-tree>')(scope);

$compile('<choice-tree ng-model="choice.children" withchildren="'+scope.withchildren+'"></choice-tree>')(scope);

http://plnkr.co/edit/5lLGIQ?p=preview

于 2012-09-20T09:57:13.917 回答