简体   繁体   中英

using promise in views in angularjs

<div ng-app="myApp" ng-controller="myCtrl">

First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{firstName + " " + lastName}}
{{obj}}

</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope ,$q,$timeout) {
    $scope.firstName = "John";
    $scope.lastName = "Doe";
    var pro=function(){
var a=$q.defer();
$timeout(function(){
console.log("resolve");
a.resolve(1);
}, 
3000
);
    return a.promise;
}

$scope.obj=pro();

});
</script>

As i study when we use promise object in view it automatically adds resolve function to show the resolve value in view but it is not showing resolved value in view.it is just showing this "{}".what is wrong i am doing

Templates no longer automatically unwrap promises

$parse and templates in general will no longer automatically unwrap promises.

For more information, see

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM