Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
angular-component
Advanced tools
Start using .component()
now!
angular-component.js is a ~1kb
script that adds component()
support in Angular 1.5 to all Angular versions above 1.3
, so you can begin using the new method now.
Note: you must include this script straight after angular.js
and before your application code to ensure the component()
method has been added to the angular.module
global.
Read about the Angular 1.5
component()
method here
This polyfill supports the following feature set of the .component()
method:
Feature | Supports |
---|---|
angular.module.component() method | Yes |
bindings property | Yes |
'E' restrict default | Yes |
$ctrl controllerAs default | Yes |
transclude property | Yes |
template support | Yes |
templateUrl injectable for $element and $attrs | Yes |
One-way data-binding emulated | Yes |
Lifecycles: $onInit , $onChanges m $postLink , $onDestroy | Yes |
require Object for parent Component inheritance | Yes |
$ prefixed properties such as $canActivate | Yes |
<div ng-app="app">
<div ng-controller="MainCtrl as vm">
<counter count="vm.count"></counter>
</div>
</div>
<script>
angular
.module('app', [])
.component('parentComponent', {
template: `
<div>
{{ $ctrl.user }}
<child-component user="$ctrl.user" on-update="$ctrl.updateUser($event);"></child-component>
</div>
`,
controller: function () {
this.user = {
name: 'Todd',
location: 'England, UK'
};
this.updateUser = function (event) {
this.user = event.user;
};
}
})
.component('childComponent', {
bindings: {
user: '<',
onUpdate: '&'
},
controller: function () {
this.$onInit = function () {
// component initialisation
};
this.$onChanges = function (changes) {
if (changes.user) {
this.user = angular.copy(this.user);
}
};
this.$postLink = function () {
// component post-link
};
this.$onDestroy = function () {
// component $destroy function
};
},
template: `
<div>
<input type="text" ng-model="$ctrl.user.name">
<a href="" ng-click="$ctrl.onUpdate({$event: {user: $ctrl.user}});">Update</a>
</div>
`
});
</script>
npm install angular-component --save
bower install angular-component.js --save
Ensure you're using the files from the dist
directory (contains compiled production-ready code). Ensure you place the script before the closing </body>
tag.
<body>
<!-- html above -->
<script src="angular-1.x.js"></script>
<script src="dist/angular-component.js"></script>
<script src="app.js"></script>
</body>
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Gulp.
require
property from 1.5 stable, restrict: 'E'
as default$
prefixed properties to factory Objectbindings
is omitted, short-circuit if .component() is already supportedFAQs
Angular component() polyfill
The npm package angular-component receives a total of 1,816 weekly downloads. As such, angular-component popularity was classified as popular.
We found that angular-component demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.