gpt4 book ai didi

javascript - templateURL 的 AngularJS 问题

转载 作者:行者123 更新时间:2023-11-30 16:09:04 28 4
gpt4 key购买 nike

我刚刚开始学习 Angular。我正在尝试使用 TemplateURL 编写 Custome 指令示例。问题是在新的自定义标签中它没有打印模板的结果。

到这个链接你可以看到代码。
索引.html

<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="it-IT">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello Angular</title>
<script src="../../angular.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</head>
<body ng-app="myApp" ng-controller="controApp as ctrl">


<table border=2>
<thead>
<td>AAA</td>
<td>BBB</td>
<td>CCC</td>
</thead>
<tbody>
<lista-clienti lista="ctrl.elencoClienti"></lista-clienti>
</tbody>
</table>

</body>
</html>

脚本.js

var app = angular.module("myApp", []);

app.directive("listaClienti", function() {
return {
scope: {
lista : "="
},
//template: "<div>missing tpl</div>"
templateURL: "selectCity.html"
};
});

app.controller('controApp', function($scope ){

$scope.elencoClienti = [
{codiceCliente: "1", ragioneSociale: "Michele Srl", indirizzo_so:"Via delle calende greche" },
{codiceCliente: "2", ragioneSociale: "Michele Srl", indirizzo_so:"Via delle calende greche" },
];


});

选择城市.html

<tr ng-repeat="c in lista">
<td>{{c.codiceCliente}}</td>
<td>{{c.ragioneSociale}}</td>
<td>{{c.indirizzo_so}}</td>
</tr>

可能是什么问题?谢谢

目录结构:05_自定义指令
-- 示例_02
----index.html
----脚本.js
----selectCity.html

最佳答案

当使用 ctrlAs 语法时,使用它代替 $scope

 this.elencoClienti  = [ 
{codiceCliente: "1", ragioneSociale: "Michele Srl", indirizzo_so:"Via delle calende greche" },
{codiceCliente: "2", ragioneSociale: "Michele Srl", indirizzo_so:"Via delle calende greche" },
];

关于javascript - templateURL 的 AngularJS 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36550012/

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