Manual Angular Bootstrap Example

Shows how to wire up Angular "after the fact."

by Stepan Kasyanenko

HTML

<div ng-cloak>
  <div ng-controller="myController">
    <input type="text" ng-model="model" /> {{model}}
    <button ng-click="reset()">Reset</button>
  </div>
</div>

JavaScript

var app = angular.module("myApp", []);
app.controller("myController", function($scope, servicesConfig) {
  console.log(servicesConfig);
  $scope.model = servicesConfig.host;
  $scope.reset = function() {
    $scope.model = '';
  };
});

angular.element(document).ready(function() {
  //Simulate AJAX call to server
  setTimeout(function() {
    app.constant('servicesConfig', {
      host: "appdev"
    });
    angular.bootstrap(document, ['myApp']);
  }, 2000);

});