angularjs-components

Where should I place code to be used across components/controllers for an AngularJS app?

旧巷老猫 提交于 2019-12-09 03:43:37
问题 Should it be associated with the app module? Should it be a component or just a controller? Basically what I am trying to achieve is a common layout across all pages within which I can place or remove other components. Here is what my app's structure roughly looks like: -/bower_components -/core -/login --login.component.js --login.module.js --login.template.html -/register --register.component.js --register.module.js --register.template.html -app.css -app.module.js -index.html 回答1: This

How to test changes on Component Bindings by parent element?

倖福魔咒の 提交于 2019-12-08 19:38:09
问题 I have a component like follows and would like to test what the $onChange method does in case the binding myBinding changes. I tried the whole morning, but could not find a way to solve this. angular .module('project.myComponent', []) .component('myComponent', { bindings: { myBinding: '<' }, template: '<div>{{$ctrl.result}}</div>', controller: myComponentController }); function myComponentController($filter, someService) { var ctrl = this; ctrl.result = 0; $ctrl.$onChange = function (changes)

Angular 1.5 component attribute presence

不羁的心 提交于 2019-12-08 16:29:27
问题 I'm refactoring some angular directives to angular 1.5-style components. Some of my directives have behavior that depends on a certain attribute being present, so without the attribute having a specific boolean value. With my directives, I accomplish this using the link function: link: function(scope,elem,attrs, controller){ controller.sortable = attrs.hasOwnProperty('sortable'); }, How would I do this with the angular 1.5-style component syntax? One thing I could do is add a binding, but

When using $compile on component, why is the scope passed through $parent?

旧街凉风 提交于 2019-12-07 01:49:02
问题 I'm trying to dynamically compile an Angular component using $compile , but the scope isn't passed to the components scope, but to the $parent scope instead. Here is a simple component that binds to a myTitle -attribute and presents it: app.component('myComponent', { bindings: { myTitle: '<' }, template: ` <div> <div>Doesn't work: {{ $ctrl.myTitle}}</div> <div>Works: {{ $parent.$ctrl.myTitle}}</div> </div>` }); Then in the controller (or directive, etc.) I compile it using $compile: app

What is the best way to pass functions between inner components in AngularJS 1.5?

房东的猫 提交于 2019-12-05 17:50:52
问题 I was wondering what is the best way to pass functions down through 2 or more levels of components? There's no simple way of skipping the function wrap when using '&' bindings? Here's an use case: angular.module('app', []).component('app', { controller: class AppController { doSomething (data) {} }, template: ` <sub-component on-do-something="$ctrl.doSomething(data)"> </sub-component> ` }) ps: I'm using ngRedux, so such scenario is very common EDIT: The problem is: for the code above to work,

When using $compile on component, why is the scope passed through $parent?

情到浓时终转凉″ 提交于 2019-12-05 08:14:58
I'm trying to dynamically compile an Angular component using $compile , but the scope isn't passed to the components scope, but to the $parent scope instead. Here is a simple component that binds to a myTitle -attribute and presents it: app.component('myComponent', { bindings: { myTitle: '<' }, template: ` <div> <div>Doesn't work: {{ $ctrl.myTitle}}</div> <div>Works: {{ $parent.$ctrl.myTitle}}</div> </div>` }); Then in the controller (or directive, etc.) I compile it using $compile: app.controller('MainCtrl', function($scope, $element, $compile) { var template = '<my-component></my-component>'

Upgrade AngularJs 1.5 to 1.6 - which exact bindings are affected by change in $compile reg controller instances?

拟墨画扇 提交于 2019-12-05 07:44:50
Documentation for a change in $compile when upgrading from AngularJs 1.5 to 1.6 states: pre-assigning bindings on component/directive controller instances is disabled by default, which means that they will no longer be available inside the constructors. — AngularJS Developer Guide - Migrating to V1.6 - $compile The upgrade example in the documentation is as follows (shortened): Before .component('myComponent', { bindings: {value: '<'}, controller: function() { //... } }) After .component('myComponent', { bindings: {value: '<'}, controller: function() { this.$onInit = function() { // ... }; } }

Angularjs 1.5 component modal with callback function that is called multiple times by embedded Object in IE11 not updating Angular binding

只谈情不闲聊 提交于 2019-12-04 05:21:20
问题 In IE 11, I have an Angularjs 1.5 modal component as below. The modal opens and on render event it calls a function outside of the angular app with a callback function contained in this component. This outside function initiates a install process which kicks off an embedded object as shown below and this then periodically calls the callback function. The issue I am having is the binding is not being updated in the template on each callback function called from the embedded object call. The

What is the best way to pass functions between inner components in AngularJS 1.5?

空扰寡人 提交于 2019-12-04 03:00:23
I was wondering what is the best way to pass functions down through 2 or more levels of components? There's no simple way of skipping the function wrap when using '&' bindings? Here's an use case: angular.module('app', []).component('app', { controller: class AppController { doSomething (data) {} }, template: ` <sub-component on-do-something="$ctrl.doSomething(data)"> </sub-component> ` }) ps: I'm using ngRedux, so such scenario is very common EDIT: The problem is: for the code above to work, each inner component controller would look like this: .component('subComponent', { bindings: {

angularjs: broadcast from directive to controller

一曲冷凌霜 提交于 2019-12-03 23:56:56
问题 Im trying to send a message from within a directive to its parent controller (without success) Here is my HTML <div ng-controller="Ctrl"> <my-elem/> </div> Here is the code in the controller which listens for the event $scope.on('go', function(){ .... }) ; And finally the directive looks like angular.module('App').directive('myElem', function () { return { restrict: 'E', templateUrl: '/views/my-elem.html', link: function ($scope, $element, $attrs) { $element.on('click', function() { console