New to AngularJS. I wonder why it setTimeoutdoesn’t work. Is this a solo job with AngularJS?
setTimeout
jsfiddle.net
<div ng-controller="MyCtrl"> <select ng-model='form' ng-options='option.value as option.name for option in typeOptions'></select> </div> <script> var myApp = angular.module('myApp',[]); function MyCtrl($scope) { //$scope.typeOptions = []; alert("hi23"); $timeout(function() { alert("hi"); $scope.typeOptions = [ { name: 'Feature', value: 'feature' }, { name: 'Bug', value: 'bug' }, { name: 'Enhancement', value: 'enhancement' } ]; $scope.form = $scope.typeOptions[1].value; }, 3000); } </script>
Thank.
you need to enter $timeout. Observe the following change:
$timeout
function MyCtrl($scope, $timeout) { .... }
See docs for more details.$timeout
In addition, this style of declaring controllers is not recommended. I would recommend re-splitting into the following ...
myApp.controller('MyCtrl', ['$scope', '$timeout', function($scope, $timeout) { .... }]);
Angular , , . Angular , , DOM .
setTimeout, , setTimeout Angular, Angular.
, $timeout, , setTimeout $scope. $apply, Angular .
JQuery-, Angular. Angular .