我是Angular的新手。我在 roles 标记内的 angular-cli.json 中添加了JS文件。文件已成功加载,但问题是我的LoginForm控制台显示:
zone.js:192未捕获的ReferenceError:未定义WYSIWYG
当我成功登录时加载它我从仪表板组件上的login-form.component.ts
this.router.navigate(['dashboard']);
路由到我的另一个组件,其中一些HTML代码是
<div id="theWYSIWYG" name="theWYSIWYG" frameborder="0" contentEditable="true" dir="rtl" ></div>
在应用程序启动时加载的js文件中定义的函数。为什么JS没有访问仪表板组件。
答案 0 :(得分:1)
如果你想在你的组件中使用javascript。你必须在@Component
之前加入PRAGMA foreign_keys = ON;
CREATE TABLE study (id INTEGER PRIMARY KEY, study_title TEXT, contact_person TEXT);
CREATE TABLE task (id INTEGER PRIMARY KEY, task_name TEXT, description TEXT);
CREATE TABLE participant (
id INTEGER PRIMARY KEY,
first_name TEXT,
last_name TEXT,
id_current_study INTEGER references study(id),
started_current_study DATE
);
CREATE TABLE study_task (
id_study INTEGER NOT NULL references study(id),
id_task INTEGER NOT NULL references task(id),
primary key (id_study,id_task)
);
CREATE TABLE participant_task (
id_participant INTEGER NOT NULL references participant(id),
id_task INTEGER NOT NULL references task(id),
status TEXT check (status in ('STARTED', 'DELIVERED', 'PASSED', 'FAILED')),
primary key (id_participant,id_task)
);
insert into study values (1, 'MX9345-3', 'John Doe');
insert into study values (2, 'MX9300-2', 'Jane Doe');
insert into participant values (1001, 'Michael', 'Smith', 1,'2018-04-21');
insert into participant values (1002, 'Julia', 'Barnes', 1, '2018-04-10');
insert into task values (51, 'OGTT', 'Make a ...');
insert into task values (52, 'PVT', 'Inspect the ...');
insert into study_task values (1,51);
insert into study_task values (1,52);
insert into study_task values (2,51);
--insert into study_task values (2,66); --would fail since 66 doesnt exists (controlled and enforced by foreign key)
然后在你的AppComponent中你可以使用myFunc调用javascript函数。
declare var require: any;
const myFunc = require('../assets/jsFile');
@Component({ ....
答案 1 :(得分:0)
import * as _ from "<jsfile_name>";
您可以在组件类型脚本文件中导入js文件