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. DMA Stream/Channel Outputting via GPIOC[0..7]

    Ok, so quickly mashing up another example using a different TIM, DMA Stream/Channel for illustration ...

  2. bat如何批量删除指定部分文件夹名的文件夹

    @echo offfor /f "delims=" %%i in ('dir /s/b/ad 123*') do ( rd /s/q "%%~i")exit

  3. Mybatis-Plus 多表联查分页

    原文:https://www.jianshu.com/p/759b6430ed5b 分析 使用的工程,依旧是 spring-boot,关于分页,官网给出了一个单表的 demo,其实多表分页实现原理相同 ...

  4. NSNotificationCenter消息注册与撤销

    苹果的消息机制是个非常好用的东西,当需要在类的各个实例之间传递消息或者写一些事件驱动的程序时,绝对是个不错的工具.但是使用时一不小心就会造成引用已经被dealloc的对象的错误,引起程序崩溃.于是,在 ...

  5. Android_深入解析AsyncTask

    转载:特别感谢浪人的星空,有部分修改! http://blog.csdn.net/hitlion2008/article/details/7983449 1.AsyncTask的内幕 AsyncTas ...

  6. sendto 和 recvfrom 函数

    sendto recvfrom

  7. IP视频通信中的"丢包恢复技术”(LPR)

    转自:http://blog.csdn.net/blade2001/article/details/9094709 在IP视频通话中,即使是在丢包率很小的情况下也会对使用效果造成较为明显的影响.正是由 ...

  8. git push.default设置

    转自:http://blog.csdn.net/daijingxin/article/details/51326715 在进行一次空仓库的提交时,我遇到了这个警告 警告如下: warning: pus ...

  9. Android之仿String的对象驻留

    String a = "abc"; String b = "abc"; a == b     true; 变量a和变量b是同一个值.这不只是说它俩的值是一样的, ...

  10. 使用Camera进行拍照 & 后台静默拍照的思路

    Android中的Camera可以用来进行自定义相机.取景框实时预览.拍照等操作.在5.0中,这个类不推荐使用了,新出了一个Camera2,那个东西没怎么研究过,反正一时半会用不到.本篇讲解的是如果用 ...