我是AngularJS的新手,所以我的錯誤可能在我的代碼中的任何地方,我找不到它。我使用$HTTP GET
方法檢索位於某個服務器/頁面中的數據。檢索完該數據(這是JSON)後,我想用該字符串來正確檢索數據,如name:number:等等。但是,有一次,我把這些數據放入$scope.listOfCompanyUsers
,我無法觸及它。如果我嘗試$scope.listOfCompanyUsers.slice(..)
或者如果我在該對象上嘗試任何其他字符串函數,我的整個網頁都會崩潰。我「alert()
」倒是在$scope.listOfCompanyUsers
,其結果是:
<pre>[
{
"admin": true,
"id": 123,
"username": "someName",
"last_name": "someLastName",
"name": "John Doe"
}
]</pre><br>
我想要做的是從字符串刪除前和BR標籤,所以我有一個純粹的JSON字符串,我可以玩,但再次任何功能我嘗試在$scope.listOfCompanyUsers
崩潰我的網站。我該怎麼辦?我試過var someOtherVariable = $scope.listOfCompanyUsers
,但那個變量稍後不工作。我添加了部分代碼,因爲我的錯誤可能在其他地方。
控制器:
$http({
method: 'GET',
url: '/someURL'
}).then(function successCallback(response) {
$scope.listOfCompanyUsers = response.data;
},
function errorCallback(response) {
alert(response.status);
});
同一個控制器上後來:
.
.
$scope.someFunction = function() {
.
.
else {
alert("Maximum of 9 other passengers!");
alert($scope.listOfCompanyUsers);
// In this alert I could see the $scope.listOfCompanyUsers as mentioned above
}
};
我的目標,現在是有一個變種objectOfUsers = [{admin: true, id:123, username: "name", last_name: "test", name: "something"}, {next user.}, .]
,但因爲我不能碰$scope.listOfCompanyUsers
我被卡住了。
而不是'alert($ scope.listOfCompanyUsers);',你能提供一個關於'console.log($ scope.listOfCompanyUsers)的結果的屏幕截圖嗎? – Cerbrus
它顯示完全一樣,無論如何我會附上一個SS。 http://imgur.com/a/wQzGj –
啊,我明白了。 'pre'和'br'標籤實際上是響應的一部分......您是否可以訪問該通話的服務器端? – Cerbrus