gpt4 book ai didi

javascript - ng-include 不显示 html

转载 作者:行者123 更新时间:2023-11-30 16:36:55 24 4
gpt4 key购买 nike

我已经创建了一个自定义的 Popup.html 页面,它将出现在当前的 index.html 页面之上。所以我在 index.html 中包含了 Popup.html,如下所示

index.html

<body ng-app="GameInformation">
<div id="completeGames" ng-controller="gameInfo">
<div ng-controller="popupInfo">
<div ng-model="popup">
<div ng-include src="'popup.html'"></div>
</div>
</div>
</div>
<div class="Row" ng-repeat="info in gameDetails | filter:searchTxt" ng-click="openGame()">
<div class="Cell">{{info.GameName}}</div>
</div>

App.js

var app = angular.module('GameInformation', []);
app.controller('gameInfo', function($scope, $http)
{
$http.get("data/GameInfo.json").success(function(response){
$scope.gameDetails = response;
}).error(function(data, status, headers, config) {});
$scope.openGame = function()
{
$scope.$broadcast('GAME_INFO_BROADCAST', this.info);
}
});

app.controller('popupInfo', function($scope)
{
$scope.$on('GAME_INFO_BROADCAST', function(event, args) {
console.log("Received ->" +args.GameName);
$scope.gameInfoPopupVisible = true;
$scope.gameDetail = args;
})
});

popup.hml

<body ng-app="GameInformation">
<div id="popup_content">
<table>
<tr>
<td valign="top">
<b>Game Name: </b>
</td>
<td valign="top">
{{gameDetail.GameName}}
</td>
</tr>
</table>
</div>
</body>

当我单击 index.html 中的表格行时,Popup.html 页面从 json 获取了全部信息。所以它工作正常。但是当调用 openGame 函数时,popup.html 没有显示在 index.html 页面中。我无法获得解决方案,如何通过 index.html 显示此自定义 popup.html?当我在 firebug 中看到 html 页面时,我意识到页面中存在 popup.html,但它的高度是 0px,宽度很好。那我该怎么做呢?请帮忙。

这是我的申请链接

http://plnkr.co/edit/hDzPMCfjfSxtVKD2xJz3?p=preview

最佳答案

您错误地使用了指令 ng-include。你应该从 popup.html 中删除 body 标签。演示:http://plnkr.co/edit/yEiwiHY7yGXqgmju7xbD?p=preview

你应该使用:

<div ng-include="'popup.html'"></div>

代替

<div ng-include src="'popup.html'"></div>

更新尝试在 gameInfo Controller 中使用 $rootScope.$broadcast('GAME_INFO_BROADCAST', this.info);。记得将 $rootScope 注入(inject) Controller :app.controller('gameInfo', function($scope, $http, $rootScope)

关于javascript - ng-include 不显示 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32591423/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com