gpt4 book ai didi

javascript - 无法在同一 HTML 中使用多个模板/ Controller

转载 作者:可可西里 更新时间:2023-11-01 13:26:29 24 4
gpt4 key购买 nike

在 Angular 应用程序中,我需要在 B.html 中包含 A.html 及其 Controller ,而不复制任何一个 A.html或 Controller 。

我在A.html中写了下面的但是没用

<div ng-include src="src/html/v1/A.html"></div>

以下是应用程序的代码结构

src
├── html
│   ├── v1
│   │   ├── A.html
│   │   ├── B.html
├── index.coffee
├── index.html
├── js
│   ├── controllers
│   │   ├── v1
│   │   │   ├── AController.js
| │   │   ├── BController.js
└── sass
├── v1

以下是 index.coffee 包含的内容 -

 $routeProvider
.when("/",
{
templateUrl: "src/html/v1/A.html",
title: "A"
controller: "AController"
})
.when("/A",
{
templateUrl: "src/html/v1/A.html",
title: "A"
controller: "AController"
})
.when("/B",
{
templateUrl: "src/html/v1/B.html",
title: "B"
controller: "BController"
})
.otherwise({ redirectTo: "/" })

请建议我在这里缺少什么。

PS:这个问题的答案可能是许多其他类似问题的答案,但我一开始找不到答案。对该问题的支持清楚地表明它具有相关性。

最佳答案

ng-includesrc 属性接受一个字符串。所以将其更改为:

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

来自docs :

angular expression evaluating to URL. If the source is a string constant, make sure you wrap it in single quotes, e.g. src="'myPartialTemplate.html'".

关于javascript - 无法在同一 HTML 中使用多个模板/ Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37371560/

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