javascript - angularjs - ng-click doesn't work inside script -
angular.module('myapp').controller('institutioncontrol', function ($scope, $rootscope,auth, $sessionstorage,$localstorage, $rootscope, $stateparams, $location, $http, $cookies,toastr,datafactory,$oclazyload,$interval) { if (!auth.is_login_sim()) { $location.path('/home'); return false; } $scope.user_auto_refreshhtml=''; $scope.islogged=auth.is_login_sim(); $scope.user_auto_refresh=''; console.log($scope.islogged); if( $scope.user_auto_refresh =='1'){ $scope.getinstitutionfilling=$interval(function(){ //alert('hello'); datafactory.post_api('institution/institutionfilling_details',{'user':auth.is_login_sim()}).then(function(results){ //console.log(results); $scope.institutionfilling_details=results.institution_details; $scope.user_auto_refresh=results.user_auto_refresh; console.log($scope.user_auto_refresh); if($scope.user_auto_refresh == '0'){ $scope.user_auto_refreshhtml='<span class="off-t" data-ng-click="updateautorefresh(sumana)" ng-value="0">off</span>'; $('#auto_refresh').html($scope.user_auto_refreshhtml); }else{ $scope.user_auto_refreshhtml=' <span class="on-t" data-ng-click="updateautorefresh(sumana)" ng-value="1">on</span>'; $('#auto_refresh').html($scope.user_auto_refreshhtml); } }); },300000); } datafactory.post_api('institution/institutionfilling_details',{'user':auth.is_login_sim()}).then(function(results){ //console.log(results); $scope.institutionfilling_details=results.institution_details; $scope.user_auto_refresh=results.user_auto_refresh; console.log($scope.user_auto_refresh); if($scope.user_auto_refresh == '0'){ $scope.user_auto_refreshhtml='<span class="off-t" data-ng-click="updateautorefresh(sumana)" ng-value="0">off</span>'; $('#auto_refresh').html($scope.user_auto_refreshhtml); }else{ $scope.user_auto_refreshhtml=' <span class="on-t" data-ng-click="updateautorefresh(sumana)" ng-value="1">on</span>'; $('#auto_refresh').html($scope.user_auto_refreshhtml); } }); $scope.updateautorefresh = function updateautorefresh($e){ //$scope.value = val; console.log($e); }; });
the element you're trying append #auto_refresh
should compiled
angular assigns respective click event element.
i've created sample application of same requirement, please check! hope helps you!
var app = angular.module('sample', []); app.controller('samplecontroller', function($scope, $compile) { $scope.user_auto_refreshhtml = $compile('<span class="on-t" data-ng-click="updateautorefresh()" ng-value="1">on</span>')($scope); $('#auto_refresh').html($scope.user_auto_refreshhtml); $scope.updateautorefresh = function() { alert('i started working'); }; });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="sample"> <div ng-controller="samplecontroller"> <div id="auto_refresh"></div> </div> </div>
Comments
Post a Comment