Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
以Angular2呈现Javascript_Javascript_Html_Angular_Paypal - Fatal编程技术网

以Angular2呈现Javascript

以Angular2呈现Javascript,javascript,html,angular,paypal,Javascript,Html,Angular,Paypal,我是angular的新手,正在尝试配置paypal。这就是我想要使用的javascript 当我将脚本主体复制粘贴到html中时,什么都没有出现 我试图将脚本放入ng onit函数中,但我不确定如何执行 component.js ngOnInit = function () { paypal.Button.render({ ... html div id=“paypal按钮容器”>这里正在工作 当您将JavaScript作为script包含在HT

我是angular的新手,正在尝试配置paypal。这就是我想要使用的javascript

当我将脚本主体复制粘贴到html中时,什么都没有出现

我试图将脚本放入ng onit函数中,但我不确定如何执行

component.js

    ngOnInit = function () 
    {
    paypal.Button.render({

        ...
html


div id=“paypal按钮容器”>这里正在工作

当您将JavaScript作为
script
包含在HTML页面中时,您不能简单地
导入
内容(在本例中为PayPal API)。但一旦您这样做,浏览器将在加载页面时加载该脚本。根据文档示例,据说在加载脚本后,全局
paypal
对象将可用。要使用Angular之前可用或未管理的全局对象,我们可以对其进行如下处理:

declare var paypal: any;

然后你可以在打字脚本中使用它。由于此第三方脚本将执行一些
渲染
,因此最好将其初始化放在
ngAfterViewInit
生命周期挂钩中。

我决定使用另一种方法。。(安圭拉的贝宝2 )





这使得paypal按钮及其所有动态元素变得简单。

默认情况下,Angular将删除除index.html之外的所有html脚本。 您可以在index.html中添加脚本,也可以使用renderr2动态添加脚本


类似的方法可以在这里找到:

组件模板中不能有脚本标记。如何添加脚本标记有几个问题和答案。“渲染”是什么意思?是否要在网页上显示源代码?渲染是javascript中的DOM选择器。我将环顾四周添加脚本标记,看看它是否修复了它。
declare var paypal: any;
<form #form class="form-inline" name="_xclick" 
action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="mmusale93@gmail.com">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="item_name" value="Paypal demo charge">
<input name="item_number" type="hidden" value="0001"/>
<input type="text" class="form-control" size="30" id="paypalAmount" name="amount"/>
<input type="hidden" name="return" value="https://localhost:4200/" />
<input type="hidden" name="cancel_return" value="https://localhost:4200/" />
<input type="hidden" name="custom" value={{title}}>
<!--pass your notification URL-->
<input name="notify_url" value="YOUR NOTIFICATION URL" type="hidden"><br/>
<br/>
<input (click)="form.submit()" type="image" 
src="https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif" border="0"
            name="submit" alt="Make payments with PayPal - it's fast, free 
and secure!"/>
</form>