When migrating AngularJS (v1.x) applications to Angular you have different options. Using Angular Elements is one of them. In this lesson we learn how to integrate an Angular Element into an AngularJS (v1.x) application. We will leverage some features release in the latest AngularJS 1.7.3 that make it fully compatible with custom elements.

Angular Element:

import {
Component,
OnInit,
Input,
Output,
EventEmitter,
AfterViewInit,
ElementRef,
Attribute,
AfterContentInit,
ChangeDetectorRef
} from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms'; @Component({
// tslint:disable-next-line:component-selector
selector: 'feedback-form',
templateUrl: './feedback-form.component.html',
styleUrls: ['./feedback-form.component.scss']
})
export class FeedbackFormComponent implements OnInit {
feedbackForm: FormGroup;
_name; @Input()
set name(val) {
this._name = val; this.feedbackForm.patchValue({
name: val
});
}
get name() {
return this._name;
} @Output()
feedbackSubmit = new EventEmitter(); constructor() {} ngOnInit() {
this.feedbackForm = new FormGroup({
name: new FormControl(this.name),
feedback: new FormControl('')
});
} onSubmit({ value, valid }) {
if (valid) {
this.feedbackSubmit.next(value);
}
}
}

Using in AngularJS:

const appModule = angular.module('myApp', []);

appModule.component('myApp', {
template: `
<h1>AngularJS < Angular</h1>
<feedback-form ng-prop-name="$ctrl.name" ng-on-feedback_submit="$ctrl.onFeedbackSubmit($event)"></feedback-form>
`,
controller: function() {
this.name = 'Juri'; this.onFeedbackSubmit = ev => {
console.log('Got ', ev.detail);
};
}
}); angular.element(function() {
angular.bootstrap(document, ['myApp']);
});

Here the important things is to know how to listen to the event and passing the prop:

ng-prop-<input_name>
ng-on-<output_name>

[Angular] Use Angular components in AngularJS applications with Angular Elements的更多相关文章

  1. angular.element方法汇总以及AngularJS 动态添加元素和删除元素

    addClass()-为每个匹配的元素添加指定的样式类名after()-在匹配元素集合中的每个元素后面插入参数所指定的内容,作为其兄弟节点append()-在每个匹配元素里面的末尾处插入参数内容att ...

  2. [Angular 2] Angular 2 Smart Components vs Presentation Components

    Both Smart Components and Presentation Components receive data from Services in entirely different w ...

  3. Angular 2 to Angular 4 with Angular Material UI Components

    Download Source - 955.2 KB Content Part 1: Angular2 Setup in Visual Studio 2017, Basic CRUD applicat ...

  4. 【js类库AngularJs】解决angular+springmvc的post提交问题

    [js类库AngularJs]解决angular+springmvc的post提交问题 AngularJS诞生于2009年,由Misko Hevery 等人创建,后为Google所收购.是一款优秀的前 ...

  5. Using RequireJS in AngularJS Applications

    http://www.sitepoint.com/using-requirejs-AngularJS-applications/ While writing large JavaScript appl ...

  6. angular的跨域(angular百度下拉提示模拟)和angular选项卡

    1.angular中$http的服务: $http.get(url,{params:{参数}}).success().error(); $http.post(url,{params:{参数}}).su ...

  7. angular 2+ 变化检测系列三(Zone.js在Angular中的应用)

    在系列一中,我们提到Zone.js,Zones是一种执行上下文,它允许我们设置钩子函数在我们的异步任务的开始位置和结束位置,Angular正是利用了这一特性从而实现了变更检测. Zones.js非常适 ...

  8. 【Angular JS】正确调用JQuery与Angular JS脚本 - 修复Warning: Tired to load angular more than once

    自己正在做一个小网站,使用Angular JS + Express JS + Mongo DB,在开发过程中,遇到一些问题,所以整理出来.希望对大家都有帮助. 这是今天解决的一个问题,Angular ...

  9. [AngularJS] Lazy loading Angular modules with ocLazyLoad

    With the ocLazyLoad you can load AngularJS modules on demand. This is very handy for runtime loading ...

随机推荐

  1. SWD and JTAG selection mechanism

    SWD and JTAG selection mechanism SWJ-DP enables either an SWD or JTAG protocol to be used on the deb ...

  2. Git 修复 bug 切换分支时,如何保存修改过的代码(即如何保存现场)?

    工作除了开发最新的版本之外还要对原来的版本做例行的维护,修修补补.于是有了在两个分支之间游走切换的问题,最新改版的代码在分支 new 上,旧版本的代码在分支 old 上,我在 new 上开发了一半,忽 ...

  3. .NET开源作业调度框架(Quartz.NET和FluentScheduler)实战项目演练

    一.课程介绍 明人不说暗话,跟着阿笨一起玩NET .本次分享课程属于<C#高级编程实战技能开发宝典课程系列>中的一部分,阿笨后续会计划将实际项目中的一些比较实用的关于C#高级编程的技巧分享 ...

  4. x86 TargetPlatform with XBAPs

    I've got a XAML Browser Hosted Application (XBAP) project that has a dependency on another project t ...

  5. 国内打不开onedrive,怎么办?

    Onedrive不能正常连接使用是由于DNS遭到污染闹的,其上传和下载文件慢也是DNS遭到污染闹的. 方法/步骤   在C盘windows/system32/drivers/etc/hosts下,用记 ...

  6. 组织安全性SQL

    BEGIN mo_global.set_policy_context ('S', '&组织ID'); END; SELECT * FROM hr_organization_units_v;   ...

  7. excel 批注

    Excel VBA之Name对象.Comment对象及字体设置等,点滴学习积累 存在的方式 百家号11-1518:46 ======================================== ...

  8. tomcat使用不同jdk的解决方法

    1,修改bin文件夹下面的catalina.bat文件,把如下内容 rem ----- Execute The Requested Command -------------------------- ...

  9. mysql error You must reset your password using ALTER USER statement before executing this statement.

    mysql修改密码Your password does not satisfy the current policy requirements 出现这个问题的原因是:密码过于简单.刚安装的mysql的 ...

  10. Java并发编程的艺术(六)——线程间的通信

    多条线程之间有时需要数据交互,下面介绍五种线程间数据交互的方式,他们的使用场景各有不同. 1. volatile.synchronized关键字 PS:关于volatile的详细介绍请移步至:Java ...