繁体   English   中英

在视图div Angularjs中包含路由提供者templateurl路径

[英]Include route provider templateurl path in view div Angularjs

我有以下路由提供商设置,例如:

$routeProvider
.when('/', {
    templateUrl: '/slapppoc/Style Library/TAC/Views/tarification/home.html',
    controller: 'homeController'
         /*
    resolve: {
        // This function will be called before any controller/views are instantiated.
        'initializeApplication': function (initializationService) {                
            return initializationService.initializeApplicationData;
        }
    }*/
})
.when('/createTarif', {
    templateUrl: '/slapppoc/Style Library/TAC/Views/tarification/createTarif.html',
    controller: 'tarificationController'
 })
 .when('/search', {
    templateUrl: '/slapppoc/Style Library/TAC/Views/tarification/Search.html',
    controller: 'searchController'
 })     
.otherwise({ redirectTo: '/' });

现在我在主视图中有这样的div设置-

<div ng-init="tab=1" >
        <div class="cb" ng-click="tab = 1">tab 1</div>
        <div class="cb" ng-click="tab = 2">tab 2</div>

        <div ng-show="tab == 1">
               How to include html templateurl path here  (createtarif.html)
        </div>

        <div ng-show="tab == 2">
                   How to include html templateurl path here  (search.html)
        </div>
</div>

编辑

我也试过像这样的ng-include指令-

<div ng-include src="'/slapppoc/Style Library/TAC/Views/tarification/createTarif.html'"></div>

但这也行不通。

所以我想在随后的div中包含来自templateurl的html。我该怎么做? 因此,在切换divs时,html内容将自动更改。

感谢帮助。

您可以查看ng-include文档https://docs.angularjs.org/api/ng/directive/ng包含示例。

还有另一种方式。 您可以添加新的元素指令并将其包括在内

像这样使用ng-include:(不带src

<div ng-include="'/slapppoc/Style Library/TAC/Views/tarification/createTarif.html'" />

代替这个

<div ng-include src="'/slapppoc/Style Library/TAC/Views/tarification/createTarif.html'"></div>


官方文档中的示例

<div ng-controller="ExampleController">
    <select ng-model="template" ng-options="t.name for t in templates">
        <option value="">(blank)</option>
    </select>
    url of the template: <code>{{template.url}}</code>
    <hr/>
    <div class="slide-animate-container">
        <div class="slide-animate" ng-include="template.url"></div>
    </div>
</div>

暂无
暂无

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

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