[Angular] Use Angular components in AngularJS applications with Angular Elements
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的更多相关文章
- angular.element方法汇总以及AngularJS 动态添加元素和删除元素
addClass()-为每个匹配的元素添加指定的样式类名after()-在匹配元素集合中的每个元素后面插入参数所指定的内容,作为其兄弟节点append()-在每个匹配元素里面的末尾处插入参数内容att ...
- [Angular 2] Angular 2 Smart Components vs Presentation Components
Both Smart Components and Presentation Components receive data from Services in entirely different w ...
- 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 ...
- 【js类库AngularJs】解决angular+springmvc的post提交问题
[js类库AngularJs]解决angular+springmvc的post提交问题 AngularJS诞生于2009年,由Misko Hevery 等人创建,后为Google所收购.是一款优秀的前 ...
- Using RequireJS in AngularJS Applications
http://www.sitepoint.com/using-requirejs-AngularJS-applications/ While writing large JavaScript appl ...
- angular的跨域(angular百度下拉提示模拟)和angular选项卡
1.angular中$http的服务: $http.get(url,{params:{参数}}).success().error(); $http.post(url,{params:{参数}}).su ...
- angular 2+ 变化检测系列三(Zone.js在Angular中的应用)
在系列一中,我们提到Zone.js,Zones是一种执行上下文,它允许我们设置钩子函数在我们的异步任务的开始位置和结束位置,Angular正是利用了这一特性从而实现了变更检测. Zones.js非常适 ...
- 【Angular JS】正确调用JQuery与Angular JS脚本 - 修复Warning: Tired to load angular more than once
自己正在做一个小网站,使用Angular JS + Express JS + Mongo DB,在开发过程中,遇到一些问题,所以整理出来.希望对大家都有帮助. 这是今天解决的一个问题,Angular ...
- [AngularJS] Lazy loading Angular modules with ocLazyLoad
With the ocLazyLoad you can load AngularJS modules on demand. This is very handy for runtime loading ...
随机推荐
- 【Unity 3D】碰撞检测
在unity3d中,能检测碰撞发生的方式有两种, 碰撞器 触发器 概念: (一)碰撞器是一群组件,它包含了很多种类,比如:Box Collider,Capsule Collider等,这些碰撞 ...
- GoDaddy Linux主机支持机房的更换
GoDaddy Linux主机支持机房的更换 http://godaddy.idcspy.com/godaddy-change-data-center GoDaddy推出中文界面后,小编发现虚拟主机有 ...
- Java 中 byte、byte 数组和 int、long 之间的转换
Java 中 byte 和 int 之间的转换源码: //byte 与 int 的相互转换 public static byte intToByte(int x) { return (byte) x; ...
- 在单链表的第i个位置后插入一个节点(阿里+腾讯等面试题总结)
时间:2014.04.26 地点:基地 ------------------------- 一.题目 题目是非常easy和基础,就是在单链表的第i个位置后插入一个节点.要求写代码,5分钟之内完毕.面腾 ...
- 在ASP.NET MVC中使用jQuery的Load方法加载静态页面的一个注意点
使用使用jQuery的Load方法可以加载静态页面,本篇就在ASP.NET MVC下实现. Model先行: public class Article { public int Id { get; s ...
- .net项目中使用Quartz
(1)在web.config中进行相关配置 <configSections> <section name="quartz" type="System.C ...
- Ubuntu14.04LTS下使用eclipse搭建Cocos2d-x的Android环境
from://http://www.58player.com/blog-2534-94136.html 最近想玩玩游戏制作,于是选择了目前流行的游戏引擎Cocos2d-x,这个东西虽然有Android ...
- windows下PHP不能开启pgsql扩展的解决方法
Tip: 环境 windows8.1 64位 + xampp1.8.1 + postgresql 9.3.6-2 第一步: php.ini中开启pgsql扩展 extension=php_pgsql ...
- 架构:Screaming Architecture(转载)
Imagine that you are looking at the blueprints of a building. This document, prepared by an architec ...
- How to Limit NodeRunner.exe High Memory, CPU Usage
roblem: NodeRunner.exe is consuming a lot of memory and CPU resulted in performance issues on ShareP ...