Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function MyController($scope, $q, $timeout) {
- this.getItem = function () {
- var deferred = $q.defer();
- deferred.resolve({
- title: 'Some title'
- });
- return deferred.promise;
- };
- $scope.item = this.getItem();
- }
- <input type="text" ng-model="item.title">
- this.getItem().then(function(result) {
- $scope.item = result;
- });
- this.getItem = function () {
- var item = {};
- // do some async stuff
- $http.get(...).success(function(result) {
- item.title = result;
- });
- return item;
- };
- $scope.item = this.getItem();
- $timeout(function(){
- $scope.item = {
- title: 'Some title'
- }; // Apply the binding
- deferred.resolve(); // Resolve promise
- },2000); // wait 2 secs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement