angularjs - How to get angular init function in JavaScript using angular.element -


my controller name viewpostonthreadcntrl , id of controller div viewpostonthreadcntr. when call ng-init function in javascript following error displayed:

uncaught typeerror: cannot read property 'getpostreplybythreadid' of undefined

view code

<section class="trdsec" ng-controller="viewpostonthreadcntrl" id="viewpostonthreadcntrl" ng-cloak>   <div ng-init="getpostreplybythreadid()">   </div> </section> 

javascript angular.element(document.getelementbyid('#viewpostonthreadcntrl')).scope().getpostreplybythreadid();

controller

app.controller("viewpostonthreadcntrl", 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.");         }      }); 

inside angular controller define function follows

$scope.getpostreplybythreadid = function(){  // logic here...  } 

delete angular.element(...) line of code


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -