ng-include不显示包含的表

时间:2018-04-09 05:59:31

标签: html angularjs html5

HTML脚本

<div>
  <select ng-model="selectView">
    <option value="empTable.html">Table View</option>
    <option value="empList.html">List View</option>
  </select>

  <div ng-include="selectView"></div>

</div>

Angular script

var angScript = angular.module("multiselectapp",[]). controller ("multicontroller", function ($scope){
var empList = [ 
  { name:"sue", gender:"female" },
  { name:"Joe", gender:"male" }
];

$scope.employees =empList;
$scope. selectView ="empTable.html";
});

empTable.htmlempList.html使用基本HTML脚本ng-repeat来显示表格和列表视图。 加载角度脚本文件,所有路径都可以通过HTML页面上显示的$scope.message="file detected in html“消息进行交叉验证。 但是表格和列表根本不显示。

建议请!

4 个答案:

答案 0 :(得分:2)

 Ng-include=" '{{selectedView}}' " 

如果无效,请尝试删除{{}}

答案 1 :(得分:0)

试试

<div ng-include src="selectView"></div>

答案 2 :(得分:0)

它似乎对我有用:

https://embed.plnkr.co/wFaG4m?p=preview

<body ng-controller="MainCtrl">
    <p>selected item is : {{selectedItem}}</p>

    <p> name of selected item is : {{selectedItem.name}} </p>

    <select ng-model="selectedItem" ng-options="item.name for item in items"></select>
    <div ng-include="selectedItem.name"></div>
</body>

var app = angular.module('plunker', []);

JS:

app.controller('MainCtrl', function($scope) {

  $scope.items = [];
  $scope.selectedItem = { name: 'a.html'};
  $scope.items = [{name: 'c.html'},{ name: 'a.html'}];

});

答案 3 :(得分:0)

$scope. selectView ="empTable.html"; 

$scope与变量名称之间存在不必要的空间。尝试删除$scope.selectView ="empTable.html";

下面的空格