简体   繁体   English

ng-controller内部的ng-include无法正常工作

[英]ng-include inside ng-controller doesn't work correctly

I have an html file with ng-includes inside 我有一个带有ng-includes的html文件

<div ng-controller="MapMenuCtrl">
    <div class="mapMenu row">
        <ng-include src="'partials/mapMenu/filterDropdown.html'"></ng-include>
        <ng-include src="'partials/mapMenu/alertDropdown.html'"></ng-include>
        <ng-include src="'partials/mapMenu/investigationDropdown.html'"></ng-include>
    </div>
</div>

The problem is that I need MapMenuCtrl for each of ng-include. 问题是我需要每个ng-include的MapMenuCtrl。 But when it is set as in example, it works, but only a half. 但是当以示例方式设置时,它可以工作,但只有一半。 For example in one of this files I use ng-model for one of $scope variables of MapMenuCtrl and it doesn't bind. 例如,在其中一个文件中,我将ng-model用于MapMenuCtrl的$ scope变量之一,并且不绑定。 I was trying to set controller for each of ng-include, but it loads 3 times, though I need only 1. I hope you understood me. 我试图为每个ng-include设置控制器,但是它加载了3次,尽管我只需要1个。希望您理解我。 I know, that my english is quite bad 我知道我的英语很差

ng-include creates a new scope. ng-include创建新的作用域。 Put an object on the controller scope and put all bindable stuf inside. 将一个对象放在控制器作用域中,并将所有可绑定的stuf放入其中。 You can call it model for example. 例如,您可以将其称为模型。 Then the bindings should work as expected. 然后绑定应按预期工作。

Here is a link for a details of the problem you face i believe: Does my ng-model really need to have a dot to avoid child $scope problems? 这是您所面临的问题的详细信息的链接: 我的ng模型是否真的需要有一个点以避免子$ scope问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM