I can make it work when hardcoding the data, like this:
$scope.ChatHistory=[];
$scope.ChatHistory.push({
IsCustomer: false,
UserText: "Please enter the category you are looking for.",
OptionItems: [
{ OptionId: "", SortOrder: "1", OptionName: "Complaint" },
{ OptionId: "", SortOrder: "2", OptionName: "Registration" },
{ OptionId: "", SortOrder: "3", OptionName: "Enquiry" }
]
});
HTML:
<ul>
<li ng-repeat="objHistory in ChatHistory track by $index"
ng-class="{'user': objHistory.IsCustomer, 'desk': !IsCustomer}">
{{ objHistory.UserText }}
<p ng-repeat="opt in objHistory.OptionItems track by $index">
{{ opt.SortOrder }} {{ opt.OptionName }}
</p>
</li>
</ul>
Now, I get the data from DB like this:
$scope.GetData = function (categoryId) {
DataFactory.GetData(categoryId)
.success(function (data,status) {
$scope.ChatHistory.push(data);
console.log(data);
})
.error(function (data, status) {
});
}
//console log
"{\"IsCustomer\":false,
\"UserText\":\"\",
\"OptionItems\":[
{\"OptionId\":1,\"SortOrder\":1,\"OptionName\":\"Complaint\"},
{\"OptionId\":2,\"SortOrder\":2,\"OptionName\":\"Request\"},
{\"OptionId\":3,\"SortOrder\":3,\"OptionName\":\"Enquiry\"}
]
}"
How to push this 'data' into the 'ChatHistory' array now. $scope.ChatHistory.push(data) is not working. No error, but nothing shows up in the html.
$scope.ChatHistory=[];