Tag: angular

打字稿和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 } […]

如何使用webpack添加jquery插件?

我使用带有角度2的webpack用于我的web应用程序我需要在我的应用程序中添加一个jquery滑块,所以我使用的是jquery插件。 我的jquery的webpack配置是 new ProvidePlugin({ jQuery: ‘jquery’, $: ‘jquery’, jquery: ‘jquery’ }) 上面的ProvidePlugin为我的应用程序提供了$和jQuery,但我还需要将jquery插件导入我的应用程序

Bootstrap无法在Angular 6应用程序中运行

我想在Angular 6应用程序中使用Bootstrap,这是我到目前为止所做的,但似乎没有任何结果: 1)使用npm安装bootstrap,jquery和popper.js。 2)在Angular.json文件中输入以下内容 “styles”: [ “src/styles.scss”, “node_modules/bootstrap/scss/bootstrap.scss” ], “scripts”: [ “node_modules/jquery/dist/jquery.slim.min.js”, “node_modules/popper.js/dist/umd/popper.min.js”, “node_modules/bootstrap/dist/js/bootstrap.min.js” … ] 我错过了什么。 这似乎没有成功。

如何将DOM附加到Angular 2组件并仍然获取封装样式

我正在升级现有的Angular 2应用程序,该应用程序大量使用JQuery插件,D3,甚至一些React组件(所有这些都使用sizzle所以我很确定它适用于所有)。 因为一次重写所有这些实际上没有意义,我试图将它们中的一些包装在Angular 2 Component中。 为了向您展示我的意思,我有一个使用Jquery将项添加到DOM的简单组件… import { Component, AfterViewInit, ElementRef } from ‘@angular/core’; declare var $:JQueryStatic; @Component({ selector: ‘px-spinner’, template: String(require(‘./spinner.template’)), styles: [require(‘!raw!stylus-loader!./spinner.styles’)] }) export class SpinnerComponent implements AfterViewInit{ constructor(public el:ElementRef){} ngAfterViewInit(){ $(this.el.nativeElement).append(“Output 2″) } } 这里的问题是样式不适用于输出2.当我看到DOM时,原因变得明显…… output 1 Output 2 由JQuery添加的DOM元素缺少_ngcontent-ylc-1=”” 。 当JQuery注入DOM时,有没有办法让Ng2添加它? 更新 问题类似于这个问题( Angular2 – 将[_ngcontent-mav-x]添加到样式中 )但我想问题是如何在ViewEncapsulation中包含注入的dom?

SystemJS:加载jQuery

我正在使用Angular2,我想包含jQuery。 systemjs.config.js (function (global) { System.config({ paths: { ‘npm:’: ‘node_modules/’, ‘jquery’: “//code.jquery.com/jquery-2.1.4.min.js” }, meta: { bootstrap: { deps: [‘jquery’] } }, ….. } 在app.module.ts中 ,我收到错误:当我放置时找不到模块’jquery’ : import $ from ‘jquery’; 我尝试使用地图而不是路径,但结果相同..

使用jQuery datepicker和Angular 2更改事件

当我使用jQuery datepicker插件并且我正在尝试使用(更改)方法来捕获更改时,我有一些问题来捕获更改事件但似乎当我使用此插件时,angular无法捕获它。 @Component({ selector: ‘foo-element’, template: ” }) export class FooComponentClass implements AfterViewInit { ngAfterViewInit():any{ $(‘#end_day’).datepicker(); } private function checkDates(e){ console.log(“Please, catch the change event ): “); } } 我已经删除了datepicker初始化并且工作正常,但是当我再次使用它时…不起作用。 有人可以帮帮我! 非常感谢。

让yadcf(用于数据表)在Angular 2(jQuery 3)中工作

我一直在使用伟大的插件yadcf作为datatables库。 我一直在使用asp.net mvc 5的视图中没有问题。 我们目前正在使用提供数据的ASP.NET Web Api将应用程序迁移到Angular 2。 我已经通过最少的更改移动了代码,并且通过将对datatables库的引用放在承载角度应用程序的index.html页面上的脚本标记中,设法使数据表正常工作。 然后,我从承载表的组件中运行下面的datatables初始化代码。 但是每当我尝试用yadcf.init做同样的事情时,我得到: Uncaught (in promise): TypeError: Cannot read property ‘replace’ of undefined 它崩溃了。 ngOnInit(){ this.table = $(‘#studyList’) .DataTable({ serverSide: true, responsive: true, processing: true, ajax: {…….. …….. } ……… }); // runs fine to here and datatables works when the following is commented out // but […]

如何添加’active’类来链接角度2

我有一个页面和部分和固定菜单。 当用户点击菜单项时,页面将滚动到相应的部分。 对于滚动,我使用https://github.com/Nolanus/ng2-page-scroll 如何在点击时将“活动”类添加到菜单项,以及当用户滚动到新部分时? 编辑:进度 – 在Click上添加’active’类: 我的HTML: item 1 在我的组件中: private activeLink: string = ‘default-active-link’; setActiveLink(link: string){ this.activeLink = link; } 但是如何让它在滚动上工作呢?

如何在Angular2 Typescript项目中全局导入Javascript库?

我正试图弄清楚如何在我的Angular2项目中导入外部库。 正如你可以看到关于这个问题的其他答案,有一些混乱,甚至Angular2文档都没有关于它的信息。 此外,Google上的任何搜索都会导致与Alpha或Beta版Angular2相关的旧结果。 我正在尝试导入Foundation和jQuery库。 我需要第一个使用一些基础代码,我需要第二个使基础JS代码工作(它使用jQuery)甚至在我的Typescript组件中使用它。 据我所知,因为即使在我的Typescript代码中我也必须使用jQuery,我需要安装jQuery的“打字版本”。 所以我有两种类型来导入Angular2项目中的外部库: 第一种方式: 我可以按照这个答案来做。 通过这种方式,我可以在我的Typescript组件中使用jQuery代码,它可以工作,因为我使用SystemJS模块加载器导入节点库,因为我安装了jQuery的typings install dt~jquery –save –global )。 第二种方式: 我在index.html文件中添加 。 我没有必要涉及SystemJS ,也没有任何SystemJS安装。 但在这种情况下我需要jQuery来运行Foundation。 我是否需要使用第一种方式再次导入jQuery? 我的意思是将到索引文件中。 无论如何,我在bootstrapping Foundation框架中遇到了一些问题,正如你在这里看到的那样 那么,我的import有什么问题? 一般来说,如何在Angular 2.0.0项目中导入外部库? 在我的例子中,如何正确导入Foundation以使用其构建块以及如何正确导入jQuery以使Foundation工作并使我能够在Typescript组件中编写jQuery代码?