我有一些從laravel控制器傳遞的正確格式的json,我想用角度遞歸地顯示它們,但ng模板中的HTML內容未呈現。怎麼了?html在ng模板中沒有呈現
注:我取代的角默認標籤{{}}與<%%>
<div id="treeViewContent" ng-init="getTreeData()">
<script type="text/ng-template" id="directoryTree">
<div class="tree-item" ng-click="loadDir(dir.address)">
<i class="fa fa-folder orange"></i>
<% dir.name %>
</div>
<ul ng-if="dir.subdir">
<li ng-repeat="dir in dir.subdir" ng-include="'directoryTree'"></li>
</ul>
</script>
<ul class="noselect">
<li>
<div class="tree-item" ng-click="loadDir('/')">
<i class="fa fa-hdd-o blue"></i>
{{ ucfirst(\Auth::user()->username) }}
</div>
<ul>
<li ng-repeat="dir in dirs" ng-include="'directoryTree'"></li>
</ul>
</li>
</ul>
</div>
和getTreeData()是:
$scope.dirs = [];
$scope.getTreeData = function()
{
$http.post("/admin/drive/treeData", {_token: csrf_code}).then(function(response)
{
if (response.status == 200)
{
$scope.dirs = response.data;
}
else
{
Flash({status: "failed", message: "Error"});
}
})
}
和JSON數據
[
{
"name":"image",
"address":"\/image",
"subdir":[
{
"name":"document",
"address":"\/image\/document",
"subdir":[
]
}
]
},
{
"name":"document",
"address":"\/document",
"subdir":[
]
},
{
"name":"movies",
"address":"\/movies",
"subdir":[
]
}
]
嗨@menhajrrt,a)看起來像'getTreeData()'應該在本地'$ scope'中的'dir'屬性。你能提供這個函數的代碼嗎? b)與此同時,您可以在開發者控制檯中檢查** directoryTree **標記的作用域是否具有任何'dir'屬性。 –
@ KonstantinA.Magg嗨,a)發佈更新,b)它的json數據是正確的,這個代碼已經在laravel 5.2中工作,但是在laravel 5.4中它有問題。我很困惑。 – Abolfazl