Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.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 如何在单击链接时包含_Angularjs_Templates_Search_Controller_Include - Fatal编程技术网

Angularjs 如何在单击链接时包含

Angularjs 如何在单击链接时包含,angularjs,templates,search,controller,include,Angularjs,Templates,Search,Controller,Include,我是AngularJS的新手,我需要通过点击链接包含另一个模板 我有一个nav.html和一个header.html。两者都包含在index.html中。 在header.html中,我有 <li class="search-box visible-md visible-lg" data-ng-include=" 'views/calls/search.html' "> calls/search.html <div class="input-group" data-ng-

我是AngularJS的新手,我需要通过点击链接包含另一个模板

我有一个nav.html和一个header.html。两者都包含在index.html中。 在header.html中,我有

<li class="search-box visible-md visible-lg" data-ng-include=" 'views/calls/search.html' ">
  • calls/search.html

    <div class="input-group" data-ng-controller="callSearchCtrl">
    <span class="input-group-addon"><i class="fa fa-search text-muted"></i></span>
    <input type="text" class="form-control" placeholder="Suchen..."></div>
    
    <div class="input-group" data-ng-controller="contactsSearchCtrl">
    <span class="input-group-addon"><i class="fa fa-search text-muted"></i></span>
    <input type="text" class="form-control" placeholder="Suchen..."></div>
    
    
    
    我必须在标题中包含另一个模板,方法是单击菜单点(即Contacts)以加载Contacts/search.html

    <div class="input-group" data-ng-controller="callSearchCtrl">
    <span class="input-group-addon"><i class="fa fa-search text-muted"></i></span>
    <input type="text" class="form-control" placeholder="Suchen..."></div>
    
    <div class="input-group" data-ng-controller="contactsSearchCtrl">
    <span class="input-group-addon"><i class="fa fa-search text-muted"></i></span>
    <input type="text" class="form-control" placeholder="Suchen..."></div>
    
    
    
    获取另一个搜索控制器

    情况是,我在标题中有一个搜索栏,我想在其中搜索加载的内容模板

    也许我解决这个问题的心态是错误的

    有人知道解决办法吗

    补充:

    现在我在导航中点击不同的ng键,如:

                <a href="#/contacts/contacts" data-ng-click="selectType('contacts')"><i class="fa fa-users"></i><span>Kontakte</span></a>
    
    
    
    但是我必须把作用域函数放在HeaderCtrl还是NavCtrl中

    顺便说一句,对不起,我的英语不好:-)

    干杯
    bambamboole

    最简单、可能也是最惯用的是@coder john所建议的

    data-ng-include="search.option"
    
    在控制器中

    $scope.search = {};
    $scope.selectType = function (type) {
        $scope.search.option = 'views/'+type+'/search.html';
    };
    $scope.selectType('calls');
    
    您的菜单选项应该调用适当的处理程序,例如

    data-ng-click="selectType('calls')"
    


    视情况而定。

    请参阅有关ng开关的文档,这可能会有所帮助。或者您也可以调用一个scope函数,该函数将更新另一个scope变量,该变量包含ng include的实际路径。希望helps@bambamboolere:添加-它需要位于两个模板共享的范围内。更一般地说,我认为您可能使用了比您需要的更多的控制器。嗯,但是我的导航栏和我的标题(带有搜索栏)使用了不同的控制器。