我有一些在我的angular项目中创建层次树的代码,我不确定在哪里可以使用这些代码。
所以只有两个代码-一个用于HTML,另一个是javascript
我使用ng new命令创建了一个angular项目,所以它生成了所有的文件。
你能指导我把这些代码放在哪里吗?
html代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>AngularJS Tree Demo</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js"></script>
</head>
<body ng-app ng-controller="SampleController">
<script type="text/ng-template" id="treeLevel.html">
<ul>
<li ng-repeat="item in items">
<input type="checkbox"
name="itemSelection"
ng-model="item._Selected" />
{{item.text}}
<div ng-include=" 'treeLevel.html'"
onload="items = item.children">
</div>
</li>
</ul>
</script>
<div ng-include=" 'treeLevel.html' "
onload="items = sourceItems">
</div>
<pre> {{sourceItems | json}} </pre>
</body>
</html>java脚本是:
function SampleController($scope) {
$scope.sourceItems = [
{
text: "Item A",
children: [
{
text: "Item A-1",
children: [
{
text: "Item A-1-1"
}, {
text: "Item A-1-2"
}
]
}, {
text: "Item A-2"
}, {
text: "Item A-3"
},
]
}, {
text: "Item B",
children: [
{ text: "Item B-1" },
{ text: "Item B-2" },
{
text: "Item B-3",
children: [
{ text: "Item B-3-1" },
{ text: "Item B-3-2" },
]
}
]
}
];
}发布于 2020-02-10 20:09:15
因此,基本上Angular与组件一起工作。组件基本上只是网站的一个独立部分,比如导航栏、侧边栏、帖子组件等。一个组件有两个主要部分,HTML文件和JS文件,两者都链接在一起。因此,基本上您刚才展示的第一段代码将位于组件的HTML和JS部分的Javascript上。
Here is more information介绍了这是如何工作的,特别是关于如何创建一个角度组件。
PS:在TS (Typescript,一种继承自Javascript但具有强类型的语言)文件中,您的Javascript将被放入其中。
我希望这对你有所帮助,如果你需要更多信息,请让我知道:D
https://stackoverflow.com/questions/60149741
复制相似问题