Asriel Pires
Asriel Pires

Reputation: 21

how initialize angularjs ng-app after page loaded

A load content from jquery ajax, that contain ng-app="" and other directive. But it does't initialize. Now, How initialize a angularJS initialize ng-app that was added after page loaded.

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
<div ng-app="" class="uk-width-3-5 uk-grid">
                    <input class="uk-width-4-5" ng-model="classe" placeholder="Nivel academico..." type="range" min="1" max="13" value="14" name="classe" required>
                    <b class="uk-width-1-5">{{classe}}ª Classe</b>
                </div>

Upvotes: 1

Views: 834

Answers (2)

user7986803
user7986803

Reputation:

<!doctype html>
<html>
<body>
  <div ng-controller="MyController">
    Hello {{greetMe}}!
  </div>
  <script src="http://code.angularjs.org/snapshot/angular.js"></script>

  <script>
angular.module('myApp', [])
  .controller('MyController', ['$scope', function ($scope) {
    $scope.greetMe = 'World';
  }]);

angular.element(function() {
  angular.bootstrap(document, ['myApp']);
});
  </script>
</body>
</html>

Sample example on how to bootstrap an application

Upvotes: 1

g.005
g.005

Reputation: 406

I think you should use angular.bootstrap. Call it when your DOM is ready and everything has been appended.

angular.bootstrap(document, ['myApp']);

This will start angular on the document, as if it had ng-app on it. You can bootstrap it to whatever element you want though.

Hope this helps

Upvotes: 2

Related Questions