Javascript Angularjs ng包括但不包括任何视图
我一直试图将我的ng设置为如下所示:Javascript Angularjs ng包括但不包括任何视图,javascript,angularjs,Javascript,Angularjs,我一直试图将我的ng设置为如下所示: <!DOCTYPE html> <html ng-app> <head> <title>Demo</title> <script type="text/javascript" src="js/lib/angular.min.js"></script> <script type="text/javascript" src="js/lib/angular-res
<!DOCTYPE html>
<html ng-app>
<head>
<title>Demo</title>
<script type="text/javascript" src="js/lib/angular.min.js"></script>
<script type="text/javascript" src="js/lib/angular-resource.min.js"></script>
<script type="text/javascript" src="js/controllers/app.js"></script>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
</head>
<body>
<h1>Airports</h1>
<div ng-controller="AppCtrl">
<div>
<div>
<ul>
<li ng-repeat="airport in airports">
<a href="" ng-click="setAirport(airport.code)">
{{airport.code}} - {{airport.name}}
</a> -
<a href="" ng-click="editAirport(airport.code)">
Editar
</a>
</li>
</ul>
<p ng-show="currentAirport">Current airpot: {{currentAirport.name}}</p>
</div>
<!--el ng include le indica que puede incluir un scope (.html)-->
<div ng-include src="formURL"></div>
</div>
</div>
</body>
</html>
最后是form.html
<div ng-show="editing">
<h3>Edit Airport</h3>
<input ng-model="editing.name" value="" class="input-xlarge"/>
</div>
Andyrooger提供的plunker无需修改即可正常工作,但是有几件事需要更改 1) 将指令用作属性时,使用ng include时不带
src
,因此它应该是ng include=“formUrl”
2) 在ng show
将HTML更改为
<div ng-show="editing.airport">
<h3>Edit Airport</h3>
<input ng-model="editing.name" value="" class="input-xlarge"/>
</div>
从您的评论来看,您的
表单URL
似乎不正确
你把它放在这条线上
$scope.formURL= 'partials/form.html';
但是你说你的form.html和index.html在同一个目录下formURL
是相对于index.html所在目录的路径。所以
- 将form.html放在partials目录中(angularexample/partials/form.html) 或
- 将
设置为formURL
$scope.formURL= 'form.html';
ng show=“editing”
。你能更具体地说什么“似乎不起作用”吗?当我点击“Editar”时,什么都不会发生,就像我没有点击它一样。plunker对你有用吗?在plunker中,它有效,但当我复制相同的代码而不做任何更改时,它就不起作用了。我的目录:angularexample angularexample/form.html angularexample/index.html angularexample/script.html下载并单击“Editar”时会遇到同样的问题谢谢,但实际上目录是:angularExample angularExample/css angularExample/img angularExample/js angularExample/js/controllers angularExample/js//controllers/app.js angularExample/js/lib
$scope.editing = {};
// Inside function
$scope.editing.airport = $scope.airports[code]
$scope.formURL= 'partials/form.html';
$scope.formURL= 'form.html';