【问题标题】:AngularJS 1.7.5 - Object doesn't support property or method 'append' in IE9AngularJS 1.7.5 - 对象不支持 IE9 中的属性或方法“附加”
【发布时间】:2018-12-31 18:42:21
【问题描述】:

我正在运行一个带有 webkit-polyfill-injector 插件的 AngularJS 1.7.5 应用程序。该问题发生在 IE9 和 Edge 的某些版本上。

IE 控制台抛出这个函数的问题

function addScriptTag(identifier, json) {

    //prep json
    var pj = JSON.stringify(json);

    //get existing
    var tag = element[0].querySelector('script[identifier="' + identifier + '"]');

    //update existing
    if (tag) {
        tag.innerText = pj;
        return;
    }

    //create new
    var newTag = document.createElement('script');
    newTag.setAttribute("type", "application/ld+json");
    newTag.setAttribute("identifier", identifier);
    newTag.append(pj);

    //add it
    var logoScriptTag = element[0].querySelector('script[type="application/ld+json"]');
    logoScriptTag.insertAdjacentElement('afterend', newTag);
}

这里是一个 webkit-polyfill-injector 插件配置

 var res = {
    mode: 'development',
    context: path.resolve(__dirname, ''),
    entry:
    {
        app: `webpack-polyfill-injector?${JSON.stringify({
            modules: ['./app/app.js'] 
        })}!`
    },

    output: {
        path: outputPath,
        publicPath: '/web/',
        filename: '[name].bundle.js',
        chunkFilename: '[name].bundle.js'
    },

    devServer: {
        contentBase: 'build',
        host:'192.168.1.101',
        port: devServerPort,
        historyApiFallback: {
            index: '/web/',
            rewrites: [
                { from: /\/soccer/, to: '/soccer.html' }
            ]
        },
        watchContentBase: true
    },
    plugins: [

        new PolyfillInjectorPlugin({
            polyfills: [
                'Promise',
                'Array.prototype.find',
            ]
        }),...

任何帮助将不胜感激!

【问题讨论】:

标签: angularjs internet-explorer webkit


【解决方案1】:

您可以尝试使用 AngularJS jqLit​​e 追加:

//create new
var newTag = document.createElement('script');
newTag.setAttribute("type", "application/ld+json");
newTag.setAttribute("identifier", identifier);
̶n̶e̶w̶T̶a̶g̶.̶a̶p̶p̶e̶n̶d̶(̶p̶j̶)̶;̶
angular.element(newTag).append(pj);

希望它不会与你的 polyfill 发生冲突。

欲了解更多信息,请参阅AngularJS angular.element API Reference - jqLite

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-15
    • 2014-10-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多