我试图从json数据中获取不同的值。
Altought我可以从中获取描述值,但我无法获得其名称值。
这是我的app.js:
.controller("detail", ["$scope", "$http", "$stateParams", function($scope, $http, $stateParams){
var config = {
headers : {
'Content-Type': 'application/json'
}
}
$http.get("http://example.com/app/detay.php?id=" + $stateParams.id, config)
.success(function(response){
$scope.description = (response[0].description);
$scope.name = (response[0].name);
})
}])
我使用的示例json数据:
[{"id":"803","name":"At Kafas\u0131","description":"<p>Kahve fal\u0131nda at kafasm\u0131 g\u00f6rmek, iyi ve mutlu bir haber alaca\u011f\u0131n\u0131za, geli\u015fmelerin hayat\u0131n\u0131za olumlu etkilerde bulunaca\u011f\u0131n\u0131n bir i\u015faretidir.Zenginli\u011fi ve bereketin sembol\u00fc olan at kafas\u0131, i\u015f ve okul hayat\u0131n\u0131zda \u00e7ok ba\u015far\u0131l\u0131 olaca\u011f\u0131n\u0131za, uzun zamand\u0131r ilgi g\u00f6sterdi\u011finiz bir ki\u015finin duygular\u0131n\u0131za kar\u015f\u0131l\u0131k verece\u011finin bir habercisidir.<\/p>\n<p>Kahve fal\u0131nda at kafas\u0131 g\u00f6rmek, i\u015f hayat\u0131n\u0131zda yorucu ge\u00e7en g\u00fcnlerin sonunda nihayet uzun bir s\u00fcredir ev sahibi olma iste\u011finiz ger\u00e7ekle\u015fecek ve \u00e7ok g\u00fczel bir eve sahip olacakt\u0131r. Maddi ve manevi olarak y\u00fckseli\u015fler sizi bekliyor.\u0130\u015f yerinizdeki ya\u015fad\u0131\u011f\u0131n\u0131z haks\u0131zl\u0131klar ve \u00e7al\u0131\u015fmalar\u0131n\u0131z\u0131n kar\u015f\u0131l\u0131\u011f\u0131 olan paray\u0131 alamaman\u0131z her ne kadar moralinizi bozsada hakk\u0131n\u0131z\u0131 yasal yollarla araman\u0131z gerekti\u011fini sak\u0131n unutmay\u0131n. A\u015fk hayat\u0131n\u0131zda karma\u015f\u0131k duygular ya\u015fayacaks\u0131n\u0131z ve se\u00e7im yapmakta olduk\u00e7a zorlanacaks\u0131n\u0131z, bu gibi d\u00f6nemlerde kalbinizin sesini dinlemeyi ihmal etmeyin.<\/p>\n<p>.Kahve fal\u0131nda at kafas\u0131 g\u00f6rmek ne anlama gelir sorusunun bir di\u011fer cevab\u0131, arkada\u015f \u00e7evrenizde olduk\u00e7 samimi oldu\u011funuz ki\u015filerin nihayet ger\u00e7ek y\u00fcz\u00fcn\u00fc g\u00f6receksiniz ve istemedi\u011finiz olaylar ile kar\u015f\u0131 kar\u015f\u0131ya kalarak olduk\u00e7a \u00fcz\u00fcleceksiniz. \u0130nsanlar\u0131, kendiniz gibi iyi g\u00f6rmeyi art\u0131k b\u0131rak\u0131n ve hayat\u0131n ger\u00e7eklerini fark etmenin zaman\u0131 geldi.<\/p>\n"}]
这是我的HTML:
<div ng-controller="detail">
<div class="overview" ng-bind-html="description">
<p>
<h2><b>Kahve Falında {{name}} Görmek</b></h2>
<br>
{{description}}
</p>
</div>
</div>
答案 0 :(得分:1)
以下是包含服务数据的JsFiddle。
使用$http
发出HTTP请求时,我建议使用promise。
$http.get("http://falimda.com/app/detay.php?id=" + $stateParams.id, config)
.then(function(response) {
$scope.description = response.data[0].description;
$scope.name = response.data[0].name;
});
JSFiddle不允许这样做,但请在IDE /代码编辑器中尝试。
答案 1 :(得分:0)
答案 2 :(得分:0)
我没有看到任何错误,但你确定你输入了正确的ng-app吗?
我认为您应该尝试测试一件事,您创建1个变量,例如$ scope.test =“test”并将其显示到UI {{test}}。
如果没有显示,我认为您应该检查您的代码是否正确使用您的应用。
谢谢, 祝你好运。
答案 3 :(得分:0)
我终于明白了。
因此我的代码中没有任何问题可以提取名称和描述。
问题是ng-bind-html="description"
内的div
。我用它来提取带有标签的描述数据到我的html。但它为{{name}}
创造了问题。因此,我将ng-bind-html="description"
移至<p>
标记,其中包含{{description}}
,一切正常。
感谢您的帮助!