dongyu4863 2016-02-09 07:24
浏览 53

在动态添加到页面后,模板不会被编译

Edit: I found the real problem and I'm working to find a solution for it. The problem is basically the fact that i angular is not able to detect the dependencies in the controller which is loaded after the on-click-event. So my controller function won't be executed.

I'm recently trying to get deeper into angularJS. Therefore I was creating some applications which were builtin on different pages. Now I tried to bring them together on one single page. Since I had those multiple apps I had to bootstrap them manually. Even thought everything works fine I want to make the whole page into a single app. And this is the point at which the problem occurs. There were three different apps on my page: The first two are directly loaded together with the the page. But the third one gets dynamically loaded by adding a div with an on-click-event. The event also loads the specific scripts like controllers and services. For some reason the loaded template isn't compiled and the raw angular expressions are displayed on the page.

Edit: This is the part in my php-programm where the scripts for the app itself are added to the page:

$jScripts = 
'<script type="text/javascript" src="' . WEBURI . '/js/select/core/core.js"></script>'."
".
'<script type="text/javascript" src="' . WEBURI . '/js/select/core/services/configFactory.js"></script>';

The core.js scripts defines the angular.module with its dependencies.

The specific spricts are added in the php Viewscript which is called by starting the click-event:

echo '
<script type="text/javascript" src="' . WEBURI . '/js/select/core/services/organisationCiFactory.js"></script>
<script type="text/javascript" src="' . WEBURI . '/js/select/organisationCiSelect/controllers/selectController.js"></script>
';

The controller looks like this:

angular
    .module('cidb.core')
    .controller('cidb.core.organisationCiSelectCtrl',
        [
            '$scope',
            'cidb.core.Config',
            'cidb.core.OrganisationCi',
            SelectCtrl
        ]
    );

The part in my php Viewscript:

<div ng-cloak="ng-cloak">
<div ng-controller="cidb.core.organisationCiSelectCtrl" >
    //My-Template
<div>
</div>

  • 写回答

1条回答 默认 最新

  • dongpan3001 2016-02-09 09:25
    关注

    You should not delay scripts loading in angularJS, link it directly to your index.html

    In production, you might want to minify your source code into a single js file

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么