Angular js会等待服务调用返回

Angular js wait for service call return

本文关键字:调用 返回 服务 等待 js Angular      更新时间:2023-09-26

我是Angular.js的新手。我有一个动态形式的简单应用程序。我在我的应用程序中使用这个插件。

我有API返回json响应与控件被加载在页面上。在success回调我分配范围变量响应,但它似乎不工作。这是我的代码http://plnkr.co/edit/YTKloQpeiTTSEx4zVIAI?p=preview

我花了几分钟来修复这个指令来观察属性的变化

 $scope.$watch(attrs.template, function(newValue, oldValue) {
   if (newValue === oldValue) { 
     return;
   }
   //  Grab the template. either from the template attribute, or from the URL in templateUrl
   (attrs.template ? $q.when($parse(attrs.template)($scope)) :
     $http.get(attrs.templateUrl, {
       cache: $templateCache
     }).then(function(result) {
       return result.data;
     })
    )

http://plnkr.co/edit/BWXlsvJ73yeTumh83wqh?p =预览