AngularJS 1.7.5-对象不支持IE9中的属性或方法“追加”

时间:2018-12-31 18:42:21

标签: angularjs internet-explorer webkit

我正在运行带有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',
            ]
        }),...

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

您可以尝试使用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