Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在 index.html的<head>里导入<script>,在默认的路由里有用,切换路由就没用了 #258

Open
751811032 opened this issue Jun 8, 2017 · 2 comments

Comments

@751811032
Copy link

比如我有一个jquery写的滑动组件,在默认的路由里,这个是有效果的,但是切换路由以后这个就没有效果了。滑动不了。

@751811032
Copy link
Author

这个我是这样解决的,在index中写一个script方法,加上方法名,然后在你要用的ts文件中声明该方法名declare var navBar: any; 然后在oninit方法中再次调用这个方法名就可以了

@ouyanglu
Copy link

ouyanglu commented Jul 1, 2017

参考你的方式,我也仿照着引入了jquery,在ts里声明了方法名,在oninit中调用了这个方法,但访问时会报错,你有遇到吗?方法确定可以声明吗?
下面是我开发的代码:
declare var func:any;
@component({
selector:'parent',
template:<input name="name" (click)= "func()"/>
})
export class ParentComponent implements OnInit{
ngOnInit() {
func = func();
}

下面是报错信息:
ERROR TypeError: co.func is not a function
at Object.eval [as handleEvent] (ParentComponent.html:4)
at handleEvent (view.ts:141)
at callWithDebugContext (services.ts:645)
at Object.debugHandleEvent [as handleEvent] (services.ts:241)
at dispatchEvent (util.ts:173)
at eval (element.ts:222)
at HTMLInputElement.eval (dom_renderer.ts:75)
at ZoneDelegate.invokeTask (zone.js:424)
at Object.onInvokeTask (ng_zone.ts:253)
at ZoneDelegate.invokeTask (zone.js:423)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants