使用异步功能更改angularjs templateUrl

问题描述

需要在templateUrl中添加加密的动态路径变量,以便使用异步的Web-Crypto加密并返回Promise,因为我尝试从resolve调用Promise函数,因为它为此提供了support。但是无法从templateUrl块更新resolve

$routeProvider.when('/portal/page/get',{
    templateUrl: '/portal/long/path/page/get',// default path
    /*templateUrl: function() {
        const response = getSecretData();
        // obvIoUsly this is not going to work as function is async
        return '/portal/long/path/page/' + response + '/get';
    }*/
    resolve: {
        urlUpdater: function($route) {
            getSecretData().then(response => {
                // As this is async function this line executes after setting templateUrl
                // So its not updating with new urlTemplate
                $route.current.templateUrl = '/portal/long/path/page/' + response + '/get';
            });
        }
    }
});

使用Web-Crypto获取加密值的基本方法

async function getSecretData() {
    let sKey;
    let sIV = window.crypto.getRandomValues(new Uint8Array(12));
    let output;
    await window.crypto.subtle.generateKey({
        name: "aes-gcm",length: 256,},true,["encrypt"]).then(function(key) {
        sKey = key;
    });

    await crypto.subtle.encrypt({
        name: "aes-gcm",iv: sIV,tagLength: 128
    },heaowInsightsAPISecretKey,"nonSecretValue")).then(function (cipherText) {
        output = btoa(String.fromCharCode.apply(null,new Uint8Array(cipherText)));
    });
    return output;
}

$route.reload()中使用resolve将无济于事,因为它将变得递归。

那么如何通过异步功能设置/更新templateUrl?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)