gpt4 book ai didi

javascript - 如何使用 AngularJS $templateCache.get()?

转载 作者:行者123 更新时间:2023-12-02 12:41:08 25 4
gpt4 key购买 nike

当我的 Angular Controller 初始化时,我需要缓存一些 HTML 文件。

根据 Angular $templateCache documentation我可以使用以下命令将 HTML 模板添加到 Angular:

$templateCache.get('templateId.html')

但我无法让它发挥作用。我尝试在 Controller 和模块 run() 函数( Plunker )内获取模板文件。但我可以在网络控制台中看到模板未获取。

app.run(function($templateCache) {
$templateCache.get('templ.html');
});

我做错了什么?

最佳答案

您必须使用 http 请求获取 html,然后才能将其存储在模板缓存中。例如:

$http.get('templ.html', {
cache: $templateCache
}).then(function(result) {
console.log(result);
});

Updated plunker code here

关于javascript - 如何使用 AngularJS $templateCache.get()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24757917/

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