My controller's name is DisplayThreadCtrl
and the id of the controller div is DisplayThreadContainer
. When I invoke the ng-init
function in JavaScript, I encounter the following error:
Uncaught TypeError: Cannot read property 'GetPostReplyByThreadId' of undefined
View Code
<section class="trdsec" ng-controller="DisplayThreadCtrl" id="DisplayThreadContainer" ng-cloak>
<div ng-init="GetPostReplyByThreadId()">
</div>
</section>
JavaScript angular.element(document.getElementById('DisplayThreadContainer')).scope().GetPostReplyByThreadId();
Controller
app.controller("DisplayThreadCtrl", function ($scope, angularService) {
$scope.GetPostReplyByThreadId = function () {
id = getUrlParameter('id');
if (id != '' && id > 0) {
var getData = angularService.GetPostReplyByThreadId(id);
getData.then(function (InnerDetail) {
$scope.InnerDetails = InnerDetail.data;
if (InnerDetail.data.CategoryId < 1)
{
window.location='/Home/Index'
}
}, function () {
});
}
else
{
window.location='/Home/Index'
}
}
Javascript:
success: function (result) {
isSuccess = result;
if (result > 0) {
angular.element('#ViewPostOnThreadCntrl').scope().GetPostReplyByThreadId();
$(e).closest("form").find("#PostText").val("");
if (ID == 0) {
alert("Post Replied successfully.");
}
else {
alert("Replied successfully.");
}
$('html, body').animate({ scrollTop: $(ID > 0 ? "#div-" + ID + "" : ".footer").offset().top }, 2000);
if (ID == 0)
$('#ShowDiv').css({ 'display': 'none' });
}
else {
alert("Post Replied Unsuccessfully.");
}
},
error: function (result) {
alert("Post Replied Unsuccessfully.");
}
});