2017-06-09 26 views
0

所以我有一個PHP變種名爲$輸出,完成回聲json_encode($輸出)當PHP輸入類似以下打印:NG-INIT角度解析錯誤,包括JSON格式

[{ 
    "title": null 
}, { 
    "title": "a b c" 
}, { 
    "title": "d e f" 
}, { 
    "title": "d f g" 
}, { 
    "title": "f g d" 
}] 

我相信這是正確的JSON

現在我使用的輸出,因爲它必須是在同一頁上所以我用下面的代碼加載通過NG-INIT結果:

> <table ng-init="values =<?php echo json_encode($output); ?>"> 
>  <tr ng-repeat="value in values"> 
>   <td>{{value}}</td> 
>  </tr> </table> 

它如下提示錯誤:

Error: [$parse:ueoe] http://errors.angularjs.org/1.4.9/$parse/ueoe?p0=values%20%3D%5B%7B

<table ng-init="values =[{" title":null},{"title":"a="" b="" c"}]"> 

等它的一個大陣列與INT很多的話。使用ABC到位一部開拓創新詞的

+0

你不能PHP代碼添加到'html',當您添加這裏面角指令(' ng-init'),它會給你分析錯誤。 [見此](https://stackoverflow.com/questions/11312316/how-do-i-add-php-code-file-to-html-html-files) – anoop

+0

@anoop是我可以擴展它.phtml擴展名文件 –

+0

您是否可以在.phtml的任何在線編輯器上重現您的錯誤\問題? – anoop

回答

0

嘗試:<table ng-init="values =[{\' title\':null},{\'title\':\'a=\"\" b=\"\" c\'}]">

+0

」>是代碼Ebubekir我怎樣才能手動改變它 –

0

您需要使用呼叫$http從服務器獲取數據。撥打電話後,請在您的控制器的$scope中設置變量,並在此變量中使用ng-repeat以顯示結果。

+0

這就是當我們向php文件發出請求時的情況,這可以讓我的PHP代碼和HTML在同一頁 –

+0

問題是如何確保JSON正確讀取正確的角度或解析正確 –

+0

是的,但你不能設置變量角度從你的$範圍直接在html文件或phtml文件或cshtml,...您需要爲此使用call $ http。 – nevradub

0

我發現這方面的工作在某種程度上.....我不知道如何,但可能幫助別人

var obj = <?php echo json_encode($output) ?>; 
     app.controller('MaCtrl', ['$scope', '$window', function($scope, $window) { 
    $scope.obj = $window.obj; 

    $scope.getMember = function(id) { 
    $scope.values = $scope.obj; 
    console.log($scope.values); 
    }; 
}]); 

<table ng-controller="MaCtrl" ng-init="getMember(id)"> 
    <tr ng-repeat="value in values"> 
     <td>{{value.title}}</td> 
    </tr> 
</table>