gpt4 book ai didi

javascript - Angular js等待服务调用返回

转载 作者:行者123 更新时间:2023-12-03 12:24:40 25 4
gpt4 key购买 nike

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

我有 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=preview

关于javascript - Angular js等待服务调用返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24266768/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com