我有这样一个需求:ChartController会生成变量,将数值赋给div的id,然后GraphController中用到div的id变量,但是GraphController中的方法需要div的id已被渲染才行。
<div ng-controller="ChartController">
<div ng-repeat="id in chart.id">
<div id="{{ id.value }}" ng-controller="GraphController"><div>
<div>
</div>
如果GraphController的xx方法被调用的时候,我查看前端的代码,div的id名称还是
<div id="{{ id.value }}"...
去除ng-controller="GraphController"后,发现div的id渲染正确
<div id="abc123"...
很奇怪!
我不建议将angular的模板语言直接放在id或者class这些属性里,可以用ng-class,ng-href,ng-src这些属性代替。
angular里的controller不是类,不能用类似楼主那样的方法直接从一个controller里新建多个类并传值给它们。
楼主需要的是directive
http://plnkr.co/edit/M1gtlySErXvSOgQayxF6?p=preview
关于directive,看这里