[英]No $$hashkey in Angular object
In ProductMenuController
I am passing Id
to get output from the server. 在
ProductMenuController
我传递Id
以从服务器获取输出。
Example: 例:
Id
, I am getting proper output; Id
,我得到正确的输出; Id
as 2, in output object $$hashkey
is missing and output is not displaying. Id
传递为2时,输出对象$$hashkey
丢失,并且输出未显示。 I have uploaded the image, in Output one $$haskey
is present, but in Output 2 $$hashkey
is missing . 我已经上传了图像,在输出1中存在一个
$$haskey
,但是在输出2中缺少了$$hashkey
。
What and why I am getting this error. 什么以及为什么我收到此错误。
HTML Code: HTML代码:
<div class="col-md-4 col-sm-4 col-xs-12" ng-repeat="product in ProductMenuCtrl.products | filter: SearchName | filter: priceRange">
<div class="" style="border: 1px solid #d8d8d8;">
<div class="">
<img src="{{product.ProductImage1}}" class="img-responsive" />
</div>
<div class="row" style="padding:0.5em">
<div class="col-md-12">
<div>
<a ui-sref="index.productDetails({productId:{{product.ProductsId}}})" class="product-name">{{product.ProductName}}</a>
<div class="row">
<div class="col-md-6">
<div class="m-t text-left pull-left">
<a ui-sref="index.productDetails({productId:{{product.ProductsId}}})" class="btn btn-xs btn-outline btn-info">Info <i class="fa fa-info-circle"></i> </a>
</div>
</div>
<div class="col-md-6">
<div class="m-t text-right pull-right">
<span class="label label-danger" style="font-size:1em">MRR: <i class="fa fa-rupee"></i> {{product["MRR"]}}</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
JS: JS:
function ProductMenuController($http , $stateParams, $scope) {
var pmenu = this;
var vm = this;
$http({
url: 'xxx/api/Product/ProductBySubCategoryId/getById?',
method: 'GET',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
params: { subCategoryId: $stateParams.subCategoryId }
}).then(function (response) {
pmenu.products = response.data;
});
}
JSON output : JSON输出:
[{
"ProductsId": 2013,
"ProductName": "Hemodiaz",
"ProductDescription": "Introduction ECG300G three channel ECG is such a kind of electrocardiograph .",
"MRR": 35000,
"ProductImage1": "w",
"ProductImage2": null,
"ProductImage3": null,
"ProductImage4": null,
"ProductImage5": null,
"BriefProduct": "\tHemodiaz Lifesciences Pvt Ltd.\tModel No:Dr Diaz HDECG300G\tMachine Type:Resting/Diagnostic\tDisplay Type:LCD\tPower Supply:Both\tWarranty In Years:1 Yr\tWarranty Available:Brand Warranty\t12\tDisplay Size( In cm):3.5\tNo. of leads:12\tRechargable Battery:Yes\tSmart Features:Smart Phone intergation",
"SubCategorysSubCategorysId": 0,
"BrandBrandsId": 0,
"Brand": null,
"Bubbles": [],
"ProductLikes": [],
"ProductReviews": [],
"SalesOrders": [],
"SubCategory": null,
"Rooms": [],
"Suppliers": [],
"BubbleGroupings": []
}, {
"ProductsId": 2014,
"ProductName": "s",
"ProductDescription": "s",
"MRR": 77,
"ProductImage1": "7",
"ProductImage2": null,
"ProductImage3": null,
"ProductImage4": null,
"ProductImage5": null,
"BriefProduct": "7",
"SubCategorysSubCategorysId": 0,
"BrandBrandsId": 0,
"Brand": null,
"Bubbles": [],
"ProductLikes": [],
"ProductReviews": [],
"SalesOrders": [],
"SubCategory": null,
"Rooms": [],
"Suppliers": [],
"BubbleGroupings": []
}]
Only the first product is displayed. 仅显示第一个产品。
hmmm what i think might be the cause is unable to render the view but the first one rendered which is weird, anyway just force the rendering using $scope.apply and $scope.digest to enforce update on the view. 嗯,我认为可能是无法渲染视图的原因,但是第一个渲染的很奇怪,无论如何只要使用$ scope.apply和$ scope.digest强制渲染即可在视图上执行更新。
A bit of explanation here 这里有点解释
Bad to do, recommend you read Todd Motto post 不好做,建议您阅读Todd Motto的帖子
If you need to use $scope, you'll likely need to listen to an event or emit one, or $watch for Model changes.
如果需要使用$ scope,则可能需要监听一个事件或发出一个事件,或者需要$ watch进行模型更改。 Based on the above, this isn't a good idea to tie Model behaviour into the Controller again.
基于以上所述,将模型行为再次绑定到Controller中不是一个好主意。 Using Controller as allows us to inject the $scope, but think about how you can abstract the same behaviour into a Factory.
使用Controller as允许我们注入$ scope,但请考虑如何将相同的行为抽象到Factory中。 The $scope Object can be dependency injected into the Controller and used if needed.
$ scope对象可以依赖注入到Controller中,并在需要时使用。
Firstly change this pmenu.products = response.data;
首先更改此
pmenu.products = response.data;
to $scope.products = response.data;
到
$scope.products = response.data;
So wrap your $scope.products = response.data;
因此包装您的
$scope.products = response.data;
with this below 与此下面
$scope.$apply(function () {
$scope.products = response.data;
});
Then update your html to use scope instead of view model 然后更新您的html以使用范围而不是视图模型
Just try it and let's see the magic. 尝试一下,让我们看看魔术。 hope it works for you
希望这对你有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.