Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angularjs ng包括但不包括任何视图_Javascript_Angularjs - Fatal编程技术网

Javascript Angularjs 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

我一直试图将我的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-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';
    

我把这个放在一个盒子里。不确定您想要什么,但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';