How to use Electron's <webview> within Angular2 app?

本小妞迷上赌 提交于 2019-12-13 02:54:55

问题


I try to use Electon's webview tag inside my Angular2 app, but when I add the src attribute binded to an Angular2 variable, the following error occurs:

Can't bind to 'src' since it isn't a known native property

This is the index.html:

<head>
    <!-- cut out stylings, metatags, etc. -->
    <script src="../node_modules/zone.js/dist/zone.js"></script>
    <script src="../node_modules/reflect-metadata/Reflect.js"></script>
    <script src="../node_modules/systemjs/dist/system.src.js"></script>
    <script src="systemjs.config.js"></script>
    <script>
        const electron = require('electron');
        System.import('app').catch(function(err){ console.error(err); });
    </script>
</head>
<body>
    <MainComponent>Loading...</MainComponent>
</body>

This is the systemjs.config.js:

(function(global) {
// map tells the System loader where to look for things
var map = {
    'app':                        'angular',
    '@angular':                   '../node_modules/@angular',
    'angular2-in-memory-web-api': '../node_modules/angular2-in-memory-web-api',
    'rxjs':                       '../node_modules/rxjs'
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
    'app':                        { main: 'main.js',  defaultExtension: 'js' },
    'rxjs':                       { defaultExtension: 'js' },
    'angular2-in-memory-web-api': { defaultExtension: 'js' }
};
var ngPackageNames = [
    'common',
    'compiler',
    'core',
    'http',
    'platform-browser',
    'platform-browser-dynamic',
    'router',
    'router-deprecated',
    'upgrade'
];
// Add package entries for angular packages
ngPackageNames.forEach(function(pkgName) {
    packages['@angular/'+pkgName] = { main: pkgName + '.umd.js', defaultExtension: 'js' };
});
var config = {
    map: map,
    packages: packages
};
System.config(config);
})(this);

This is the Angular2 component template I (want to) use webview in:

<div class="stage-component component">
    <webview *ngIf="iFrameUrl" src="{{iFrameUrl}}"></webview>
</div>

How can I introduce the webview element to Angular2?


回答1:


If this appears, use "attr" before.

<webview *ngIf="iFrameUrl" attr.src="{{iFrameUrl}}"></webview>



回答2:


That is strange. It sounds like you maybe have a version issue. You can try to use the loadUrl api instead and see if that helps.

<script>
  onload = () => {
    const webview = document.getElementById('foo');
    webview.loadUrl('http://example.com')
</script>


来源:https://stackoverflow.com/questions/37793412/how-to-use-electrons-webview-within-angular2-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!