Tag: typescript

从Javascript调用组件中的方法 – Angular2

我需要从我在同一组件的构造函数中编写的Javascript调用我的Angular组件中声明的方法。 我的目标是检测文件输入字段的更改并通过服务将文件上传到服务器。 我在导入后添加了这个声明。 declare var $: any; 在我的构造函数中,我编写了以下代码。 $(document.body).on(“change.bs.fileinput”, “.fileinput-exists”, function () { console.log($(this).parent().find(‘.myImage’).val()); let input = $(this).parent().find(‘.myImage’); this._photoToBeSaved = input.prop(‘files’)[0]; console.log(“my file = ” + this._photoToBeSaved); //upload the image () => { this.uploadPhoto(this._photoToBeSaved); } }); 以下是同一组件中的uploadPhoto方法。 uploadPhoto(photo: any) { console.log(“here i am at upload method); // call service method to upload ….. } 但是,这不起作用。 […]

Angular2 / typescript中的Jquery轮播方法错误

我已经安装了jquery并正确导入它。 在我的应用程序的某个地方,我有一行如下, $(‘#myCarousel’).carousel(“next”); 当我执行npm start ,它会抛出错误 ‘JQuery’类型中不存在属性’carousel’。 在Typescript中如果做$(‘#myCarousel’). ,**它表示适当的** intellisense,但未列出此方法。 如果我评论该错误生成行,请执行npm start一切正常,然后如果我取消注释该行并刷新它,它将起作用。 它是打字稿编译错误。 怎么解决????

Angular 2使用数据编译动态模板

我正在为jquery网格控件开发类似接口的桥接器。 使用以下语法呈现网格并按预期工作。 … … 在t-column标签内提供渲染模板的支持时,我能够获取数据和jquery元素。 jQuery元素 现在,该按钮显示template文本。 如何动态更改来自gridData的输入元素值。 export class TemplateElement { private context: any; __parent: tComponents; constructor(protected el: ElementRef) { } ngOnInit() { template.render = (self, selector, data, index, prop) => { let templateObject = self.angularTemplate; if (!templateObject || !templateObject[selector]) { templateObject = templateObject || {}; templateObject[selector] = { key: t.getGuid(‘angulartmpl’), itemData: [], views: […]

Angular2:从javascript函数调用组件方法

目前我正在尝试使用jQuery和我的Angular2项目实现bootstrap datepicker。 这是我到目前为止: import {Component, AfterViewInit, Injector, Inject} from ‘@angular/core’; import {ObservableService} from “../../../services/data-observable.service”; declare var $:any; @Component({ selector: ‘date-range’, moduleId: module.id, template: “ }) export class DateRange implements AfterViewInit { options = { locale: { format: ‘YYYY-MM-DD’ }, startDate: ‘2013-01-01’, endDate: ‘2013-12-31’}; constructor(@Inject(Injector) private injector: Injector, @Inject(ObservableService) private _observable: ObservableService) { } ngAfterViewInit() { […]

打字稿和jquery ajax

我有以下function: 更新:添加返回$ .ajax searchAjax({url = ‘app/php/check.php’, data}: {url: any, data: any}): any { return $.ajax({ url: url, type: ‘post’, dataType: ‘text’, data: { data }, success: function (return_data) { return String(return_data); }, error: function (xhr, status, error) { var err = eval(“(” + xhr.responseText + “)”); console.log(err.Message); return err.Message; } }); } 现在,check.php返回echo’hi echo ‘hi’ […]

将jQuery脚本与Angular 6 CLI项目一起使用

我正在使用角度6开发应用程序。我的应用程序使用Minton主题 。 我在我的angular项目的index.html文件中包含了所有主题脚本。 但是当我登录或在路由之间导航时,一些jquery方法无法正常工作。 我不得不手动刷新页面以使它们工作。 有没有解决这个问题? 我找不到任何有效的解决方案了。 项目组件结构 app -components –footer –left-side-bar –header –pages —dashboard —-home —-accounts —login index.html文件 Logical Position var resizefunc = []; app.routing.module.ts文件 import { NgModule } from ‘@angular/core’; import { RouterModule, Routes } from ‘@angular/router’; import { DashboardComponent } from ‘./components/pages/dashboard/dashboard.component’; import { LoginComponent } from ‘./components/pages/login/login.component’; import { UnAuthGuardService } […]

ngFor之后的Angular 2火灾事件

我正在尝试使用jQuery插件替换Angular 2中某些动态元素中的默认滚动条。 这些元素是使用ngFor循环创建的,也就是说我无法将jQuery事件附加到创建的元素上。 在某些时候,应用程序会改变一个Observable对象,该对象在ngFor中ngFor以呈现视图。 现在,我想知道Angular何时完成绘制我的元素,以便我可以运行jQuery插件。 我不想在HTML模板中包含任何javascript。 我不想使用ngAfterViewInit ,因为这个钩子被触发了太多次 我不想实现基于setTimeout的解决方案(我认为它不可靠) 我通过使用以下自定义Pipe找到了一个解决方案:在模板的ngFor周期结束时,我写道: {{i | FireStoreEventPipe:’EVENT_TO_BE_FIRED’}} FireStoreEventPipe位置如下: transform(obj: any, args:any[]) { var event = args[0]; //Fire event return null; } 但是这个解决方案并不能让我满意。 有什么更好的方法吗? 谢谢

在TypeScript / Angular 4中导入jQuery插件’jquery.shorten’

我想在使用npm的 Ionic项目中使用名为jquery.shorten的jQuery插件。 installig的命令是npm install jquery.shorten –save 。 我成功地包含了jQuery ,我可以在我的项目中使用它。 但是无法使用jquery.shorten 。 以下是我用来包含jQuery和jquery.shorten的代码。 它位于角度项目的app.module.ts中 – import * as $ from ‘jquery’; import ‘jquery.shorten’; 我在控制台看到的错误是 – 未捕获错误:找不到模块“jquery.shorten” 我也试过以下。 这次所有控制台错误消失了。 但我找不到使用它的方法。 import * as shortMe from ‘jquery.shorten’; 它应该用作$(“.dynamic-multiple-elements”).shorten() 。 我已经遵循了一些指示来包含它。 但似乎没有任何效果。 我可以在node_modules看到文件夹jquery.shorten和必需的js文件。 我将无法使用此解决方案,因为我的元素是动态的,而且很多。

循环使用枚举,TypeScript和JQuery

您好我试图使用TypeScript和JQuery开发一个直接的待办事项应用程序。 我有一个列出任务类型的枚举: export enum TaskType { FrontEnd, BackEnd, Designer }; 然而,使用jquery.each或for循环遍历emum,我得到以下结果,(值然后索引): FrontEnd, BackEnd, Designer, 0, 1, 2 以下是我通过枚举循环的代码: constructor(e?: Object) { var template = this.FormTemplate; $(e).append(template); var sel = template.find(‘select’); /*$.each(TaskType, function (index, el) { sel.append(“” + el + “”); });*/ for(var i=0; i < (typeof TaskType).length; i++){ sel.append("” + TaskType[i] + “”); } } […]

在typescript中使用成功回调$ .get时,无法将数据绑定到类变量

我正在使用TypeScript 。 我试图将来自rest API的响应绑定到ViewModel的变量,如下所示: export class TestListViewModel { public personItems: KnockoutObservableArray; constructor() { this.personItems = ko.observableArray([]); this.person1 = new Person(); this.person1.name = ko.observable(“Test 1”); this.person1.ssnId = ko.observable(“1234”); this.personItems.push(this.person1); //If i put a debugger here and see the “this.personItems()” in console //I can see 1 object in personItems $.get(“https://somerestapi/api/TestLists”, (data: any) => { for (var index […]