<!doctype html><html ng-app><head><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.3/angular.min.js"></script></head><body><div><label>Name:</label><input type="text" ng-model="yourName" placeholder="Enter a name here"><hr><h1>Hello {{yourName}}!</h1></div></body></html>
var $compile = ...; // injected into your codevar scope = ...;var html = '<div ng-bind="exp"></div>';// Step 1: parse HTML into DOM elementvar template = angular.element(html);// Step 2: Traverse the DOM and collect all of the directivesvar linkFn = $compile(template);// Step 3: link the compiled template with the scope.linkFn(scope);
asyncCall(function(err, data1){if(err) return callback(err);anotherAsyncCall(data1, function(err2, data2){if(err2) return calllback(err2);oneMoreAsyncCall(data2, function(err3, data3){if(err3) return callback(err3);doSomething(data3);});});});
asyncCall().then(function(data1){return anotherAsyncCall(data1);}).then(function(data2){return oneMoreAsyncCall(data2);}).then(function(data3){doSomething(data3);}).fail(function(err) {// handle any error resulting from any of the above calls});Even BetterasyncCall().then(anotherAsyncCall).then(oneMoreAsyncCall).then(doSomething).fail(function(err) {// handle any error resulting from any of the above calls});
var loadAppAfterAllDataLoaded = function() {if($rootScope.bahmniConfiguration && $rootScope.encounterConfiguration && $rootScope.patientConfiguration)loadApp();}configurationService.getAll(function (data, error) {if(error) showError(error);$rootScope.bahmniConfiguration = data;loadAppAfterAllDataLoaded();});configurationService.getEncounterConfig(function (data, error) {if(error) showError(error);$rootScope.encounterConfiguration = angular.extend(new EncounterConfig(), data);loadAppAfterAllDataLoaded();});configurationService.getPatientConfig(function (data, error) {if(error) showError(error);$rootScope.patientConfiguration = angular.extend(new PatientConfig(), data);loadAppAfterAllDataLoaded();});
var configurationPromise = configurationService.getAll().success(function (data) {$rootScope.bahmniConfiguration = data;});var encounterConfigPromise = configurationService.getEncounterConfig().success(function (data) {$rootScope.encounterConfiguration = angular.extend(new EncounterConfig(), data);});var patientConfigPromise = configurationService.getPatientConfig().success(function (data) {$rootScope.patientConfiguration = angular.extend(new PatientConfig(), data);});return $q.all([configurationPromise, encounterConfigPromise, patientConfigPromise).then(loadMyApp, showError);