【发布时间】:2015-10-30 09:02:07
【问题描述】:
我对 Angular 还很陌生,但我的第一个应用程序已经很顺利了。它相当复杂,因此我提供了一个非常简化的示例来解释我的问题。
我有一个这样的 Angular 模板;
<html>
<head>
...
</head>
<body ng-controller="MyController">
<h1>My Template</h1>
<ol id="menu">
<li ng-repeat="section in sections" ng-click="goTo($index)">{{section.name}}</li>
</ol>
<div id="wrapper">
<?php echo $html; ?>
</div>
</body>
</html>
这个想法是有序列表将像一个菜单一样显示当前部分并隐藏所有其他部分。我的 PHP 脚本从现有的 HTML 创建部分,如下所示;
<section>
<h1>Page 1</h1>
<p>Some text here</p>
</section>
<section>
<h1>Page 2</h1>
<p>Text for page 2</p>
</section>
我想以某种方式使用 Angular 本身来执行以下操作;
- 向纯 HTML 添加 Angular 标记
- 从每个部分的第一个 H1 标记中获取文本并使用它来填充 scope.sections
我猜最终的结果应该是这样的;
<html>
<head>
...
</head>
<body ng-controller="MyController">
<h1>My Template</h1>
<ol id="menu">
<li ng-repeat="section in sections" ng-click="goTo($index)">{{section.name}}</li>
</ol>
<div id="wrapper">
<section ng-if="currentSection == 1">
<h1>Page 1</h1>
<p>Some text here</p>
</section>
<section ng-if="currentSection == 2">
<h1>Page 2</h1>
<p>Text for page 2</p>
</section>
</div>
</body>
</html>
我意识到我可以用一些 PHP 字符串替换来完成第一部分,但我想知道在实际项目中是否有 Angular 解决方案,PHP 替换是不可行的。
任何指针将不胜感激!
【问题讨论】:
标签: javascript php html angularjs