Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.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 有角度的ng include不工作_Angularjs - Fatal编程技术网

Angularjs 有角度的ng include不工作

Angularjs 有角度的ng include不工作,angularjs,Angularjs,我正在尝试使用ng include为我的web应用程序中的弹出窗口创建一些局部布局。但是,由于某些原因,我在执行include时没有看到HTML被呈现。这是我的覆盖服务添加ngInclude后的HTML <div id="cover" class="" ng-include="'/Angular/views/gears.html'"></div> 您给出的是一个绝对路径:/Angular/views/gears.html。 如果视图与index.html页面处于同一级别

我正在尝试使用ng include为我的web应用程序中的弹出窗口创建一些局部布局。但是,由于某些原因,我在执行include时没有看到HTML被呈现。这是我的覆盖服务添加ngInclude后的HTML

<div id="cover" class="" ng-include="'/Angular/views/gears.html'"></div>

您给出的是一个绝对路径:/Angular/views/gears.html。 如果视图与index.html页面处于同一级别,请尝试仅键入views/gears.html。 请查看您的网络选项卡chrome console、firebug或任何其他,以便
查看您的模板是否加载了Ajax请求

在以下情况下,不要将ng include指令动态附加到元素,而是直接将该指令附加到标记中的div,然后使用ng显示/隐藏:


或者,只需在OverlyService中创建一个元素,并使用angular的内置函数将其附加到DOM中。我假设应用程序中使用了一个且只有一个覆盖元素,并且它完全由覆盖服务控制。

使用服务动态添加?这是什么意思?显示更多代码!你的意思是说你正在动态地将ng include属性附加到你的div上吗?@JonathanWilson是的,确切地说,我不确定这样做是否正确。正如我在编辑中所说的那样,如果我手动将属性放入HTML中,我就可以使功能正常工作。但是我希望它是动态添加的,所以我尝试过这样做,但是我看不到div发生了什么,因为Angular已经将它从DOM中删除,并将其替换为如果在div的位置看到注释,那是因为div已经从DOM中删除了。这意味着,如果布尔值为false,将传递给ng。从ng if切换到ng show,如果您仍然希望能够检查隐藏的div。除非我从未添加您的ng if。。我仍然只是在DOM中,在我的控制器中,我有一个覆盖服务,它有一个url属性,当overlay.showurl被调用时会被修改,好的。所以我假设在您的控制器中,您正在执行以下操作:函数$scope,overlyservice{$scope.overlay=overlyservice;}。是吗?是的,我有,但它仍然没有呈现,只是显示一个注释
app.factory('overlayService', [function () {

        var overlay = {};
        var _cover;
        var _innerContent;

        jQuery(document).ready(function () {
            _cover = jQuery(document.createElement('div')).attr({ 'id': 'cover', 'ng-include' :''}).prependTo(jQuery('#mainContent'));
        });


        overlay.show = function (templateUrl) {
                jQuery(_cover).addClass('show');

                jQuery('html,body').bind('mousewheel DOMMouseScroll', function (event) {
                    event.preventDefault();
                });

                //_cover.attr('ng-include', "'/Angular/views/"+templateUrl+"'");
                overlay.url = templateUrl;

                return _cover;
            }


          overlay.destroy = function () {
                    jQuery('html,body').unbind('mousewheel DOMMouseScroll');
                    jQuery(_cover).removeClass('show');

                }

          return overlay;

    }]);
<div 
    ng-if="myService.someBoolCheck('cover')" 
    ng-include="'/Angular/views/gears.html'"></div>