[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 ...
随机推荐
- Java 中 byte、byte 数组和 int、long 之间的转换
Java 中 byte 和 int 之间的转换源码: //byte 与 int 的相互转换 public static byte intToByte(int x) { return (byte) x; ...
- [.NET] [.net 脱壳工具]Sixxpack 最新脱壳机 通杀Sixxpack全版本by -=Msdn5 君临=
[.net 脱壳工具]Sixxpack 最新脱壳机 通杀Sixxpack全版本by -=Msdn5 君临=- 识别方法: 如果无法调戏,请上传附件艾特我.............发帖不易啊..身处大西 ...
- Unity3D实践系列02,查看Scene窗口物体
删除"Hierarchy"窗口中的"Directional Light". 把鼠标放在"Scene"窗口,滑动鼠标滚轮,可以对"S ...
- 为在Windows Azure上的网站配置自定义域名
本篇体验给Windows Azure上的网站自定义域名,首先"CNAME"和"A记录"是必须了解的概念. 假设,在Windows Azure上的网站域名是:x. ...
- QML与C++交互:在qml中使用QSqlQueryModel显示数据库数据
QML与C++交互:在qml中使用QSqlQueryModel显示数据库数据 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 參考链接: http:// ...
- Android布局分析工具HierarchyView的使用方法
本文是从这里看到的:http://www.2cto.com/kf/201404/296960.html 如果我们想宏观的看看自己的布局,Android SDK中有一个工具HierarchyView.b ...
- android获取屏幕长宽的方法
package com.kale.imageview02; import android.annotation.SuppressLint; import android.app.Activity; i ...
- Java命令学习系列(一)——Jps
jps位于jdk的bin目录下,其作用是显示当前系统的java进程情况,及其id号. jps相当于Solaris进程工具ps.不象”pgrep java”或”ps -ef grep java”,jps ...
- ADB与AVD的常见问题
一.adb问题常用解决方法 若是模拟器启动正常,但是adb检测不到模拟器,我们给他一套不解释连招,下面教大家几招基础拳法. 1.基础拳法一:循环自动检测 下图那个小按钮,点它,狠狠的点它,然后点运行, ...
- [转]php rsa加密解密实例
转自:http://blog.csdn.net/clh604/article/details/20224735 php服务端与客户端交互.提供开放api时,通常需要对敏感的部分api数据传输进行数据加 ...