Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs Angular JS:通过控制器添加新html内容时,ng单击不起作用_Angularjs - Fatal编程技术网

Angularjs Angular JS:通过控制器添加新html内容时,ng单击不起作用

Angularjs Angular JS:通过控制器添加新html内容时,ng单击不起作用,angularjs,Angularjs,我一直在做一个项目,在这个项目中,使用AngularJSHTML内容必须附加到一个div中,但是使用这种方法,ng单击不起作用。我用谷歌搜索了很多东西。在将Html附加到div之前也尝试过使用$compile,但遗憾的是没有成功 请看下面的代码,如果有什么可以帮助的,请告诉我 <div id="tileLayout" style="width: 198px; height: 173px;" ng-controller="TileController" ng-init="init(1000

我一直在做一个项目,在这个项目中,使用AngularJSHTML内容必须附加到一个div中,但是使用这种方法,ng单击不起作用。我用谷歌搜索了很多东西。在将Html附加到div之前也尝试过使用$compile,但遗憾的是没有成功

请看下面的代码,如果有什么可以帮助的,请告诉我

 <div id="tileLayout" style="width: 198px; height: 173px;" ng-controller="TileController" ng-init="init(1000,@ViewBag.Index, 'UTILTS')" ng-click="openTab('UTILTS.TABVIEW.TABTITLE',param = { id:@ViewBag.Index, status:'', titleStatic: '@ViewBag.Direction' })">
<div style="height: 35px;"><span class="text-left"><img src="@Url.Content("~/Images/Icons/utilts_icon.png")" alt="" style="width: 35px; height: 35px;"></span><span class="text-center">&nbsp;&nbsp;{{data.title}}</span></div>
<div>
    <div style="padding-top: 3px; padding-bottom: 3px;"><span class="text-left" style="font-size: 10px;">{{(data.title1 | translate) || "N/A"}}</span><span class="pull-right" style="font-size: 10px;">{{data.loaded}}/{{data.loadedTotal}}</span></div>
    <input type="hidden" ng-model="data.param1" />
        <div id="progressbar1" kendo-progress-bar="progressBar" class="progressBar" style="font-size: 10px;" k-min="0" k-max="100" ng-click="openTab('UTILTS.TABVIEW.TABTITLE', param = {id:@ViewBag.Index, status:data.param1})" stop-click-event></div>
</div><div>
js由用于将html代码附加到div的代码组成

  var elem = $("<div id=\"tileInstance_" + tileId + "\" class=\"item w2 h2\" ng-click=\"alert('moi')\">" +
                        "<div class=\"dashboard_tile\" style=\"height: 25px;\">" +
                        "<div>" +
                        "<div class=\"dashboard_tile title\">{{'TILE.COMPANY_SELECTION' | translate}}</div>" +
                        "<div style=\"float:right; display:inline-block;\" class='ui-icon ui-icon-closethick ui-removable-tile' popover=\"{{'TILE.REMOVE_TOOLTIP' | translate}}\" popover-trigger=\"mouseenter\" popover-placement=\"top\"></div>" +
                        "<div style=\"float:right; display:inline-block;\" class='ui-icon ui-icon-gear ui-configurable-tile' ng-click=\"openConfig(id = " + tileId + ", '" + tiledata.prefix + "')\" popover=\"{{'TILE.CONFIGURE_TOOLTIP' | translate}}\" popover-trigger=\"mouseenter\" popover-placement=\"top\"></div>" +
                        "</div>" +
                        "</div>" +
                        "<div>" +
                        data +
                        "</div>" +
                        "</div>");

                        //console.log("Packery container: " + $rootScope.container['tab-' + tiledata.tabId]);

                        var $items = $compile(elem)($scope);
                        $rootScope.container['tab-' + tiledata.tabId].append($items);
                        $rootScope.container['tab-' + tiledata.tabId].packery('appended', $items);

                        //service.InitializeTiles(tiledata.tabId);

                        $rootScope.container['tab-' + tiledata.tabId].packery();

                        service.InitializeTiles(tiledata.tabId);
                        service.InitializeTabs(tiledata.tabId);

我使用container将html代码附加到packer中。div确实会附加到容器/div,但ng单击不起作用。我也尝试过使用普通的$id.append$项,但也没有成功。

查看您的代码,它不起作用的一个原因可能是使用不正确的$scope编译html。

您似乎在使用JQuery和Angular的组合。我不确定这是否是正确的方法。您可以发布openTab函数的代码吗?另外,请看一看这可能是有用的。您能确保您正在将正确的作用域注入此模块吗?由@Sagar Waghpost提问comments@utility我试着在评论中发表质疑,但它不允许我发表评论,并且显示你必须有50个声誉才能发表评论。不确定是否有其他方法可以直接向问题添加评论。请支持同样的建议。