Javascript 带有templateURL的AngularJS问题
我刚开始学习一点。我正试图用TemplateURL编写一个Custome指令的示例。问题在于,在新的自定义标记中,不会打印模板的结果 您可以查看此链接的代码。Javascript 带有templateURL的AngularJS问题,javascript,angularjs,Javascript,Angularjs,我刚开始学习一点。我正试图用TemplateURL编写一个Custome指令的示例。问题在于,在新的自定义标记中,不会打印模板的结果 您可以查看此链接的代码。 Index.html <!doctype html> <html xmlns="http://www.w3.org/1999/xhtml" lang="it-IT"> <head> <meta http-equiv="Content-Type" content="text/html
Index.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>
你好,安格尔
AAA
BBB
CCC
script.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" },
];
});
var-app=angular.module(“myApp”,[]);
指令(“listaClienti”,function(){
返回{
范围:{
lista:“=”
},
//模板:“缺少第三方物流”
templateURL:“selectCity.html”
};
});
应用控制器('controApp',功能($scope){
$scope.elencoClienti=[
{codiceCliente:“1”,ragioneSociale:“Michele Srl”,indirizzo_èso:“Via dele calende greche”},
{codiceCliente:“2”,ragioneSociale:“Michele Srl”,indirizzo_èso:“Via dele calende greche”},
];
});
selectCity.html
<tr ng-repeat="c in lista">
<td>{{c.codiceCliente}}</td>
<td>{{c.ragioneSociale}}</td>
<td>{{c.indirizzo_so}}</td>
</tr>
{{c.codiceCliente}}
{{c.ragioneSociale}}
{c.indirizzo_so}
有什么问题吗?
谢谢
目录结构:
05_自定义_指令--示例_02
----index.html
----script.js
----选择city.html当使用ctrlAs语法时,请使用this而不是$scope
<tr ng-repeat="c in lista">
<td>{{c.codiceCliente}}</td>
<td>{{c.ragioneSociale}}</td>
<td>{{c.indirizzo_so}}</td>
</tr>
this.elencoClienti = [
{codiceCliente: "1", ragioneSociale: "Michele Srl", indirizzo_so:"Via delle calende greche" },
{codiceCliente: "2", ragioneSociale: "Michele Srl", indirizzo_so:"Via delle calende greche" },
];
请粘贴应用程序的目录结构,我的预感是指令找不到selectCity.html。我已经添加了目录结构;)你能把你的selectCity.html改成下面的
{{c.codiceCliente}{c.ragioneSociale}{c.indirizzo_so}}这是一个测试
这会告诉我们你的模板是否被注入。没什么,不起作用…我还认为这是注入的问题。你试过相对的url/selectCity.html
,这是一个url,当您使用ng controller
中的as
子句时,它建议您将属性绑定到对象,而不是$scope
。啊,很好,我不知道这个替代方法