在脚本中使用角度模型数据

时间:2015-02-03 07:53:55

标签: javascript html angularjs

我需要一些控制器模型数据共享的帮助。

在HTML中我可以通过{{block.title}}访问数据,但在html中我有一些javascript来打开外部文件:

<div class="container">
    <accordion close-others="oneAtATime">
        <accordion-group ng-repeat="block in report.blocks" is-open="block.$$isOpen">
        <accordion-heading>{{block.tags}}
        </accordion-heading>
        <script>
        $(function() {
            $("#includedContent").load("res/filename.html");
        });
        </script>
        <div id="includedContent"></div>
       </accordion-group>
   </accordion>
</div>

我想要的是使用block.title的当前值(在ng-repeat内)取代filename.html,如:

load("res/{{block.title}}.html")

我怎样才能实现这一目标?

谢谢。

1 个答案:

答案 0 :(得分:2)

你可以相对轻松地实现角度,不需要jQuery。

<div id="includedContent" ng-include="getPartial(block.title)"></div>

在您的控制器中

$scope.getPartial = function(file) {
    return "res/"+file;
};