angularjs-directive

ng-change not working on a text input

梦想的初衷 提交于 2019-12-05 08:32:50
问题 I am new to angular js. In my code there is color picker initialized from a text field. User changes the value of color and I want that color to be reflected as a background of a text in a span. It is not working. What is missing? HTML: <body ng-app=""> <input type="button" value="set color" ng-click="myStyle={color:'red'}"> <input type="button" value="clear" ng-click="myStyle={}"> <input type="text" name="abc" class="color" ng-change="myStyle={color:'green'}"> <br/> <span ng-style="myStyle"

AngularJs Directives Loaded Event

让人想犯罪 __ 提交于 2019-12-05 08:17:47
I have just started using AngularJs directives, using the resources here , here and here . I have a situation where i need to do something after all directives have been loaded. i.e Scenario 1 Controller Loads Directive 1 loads Directive 2 loads Final event fires (preferably picked up by the controller) Scenario 2 Controller loads Directive 1 loads Directive 2 loads Directive 3 loads Final event fires (preferably picked up by the controller) I can't seem to find a 'directives loaded' event. With a search, the best I could find was this SO post , (for which this answer does work), but it feels

How to recompile a directive upon inserting into DOM (angularjs)

こ雲淡風輕ζ 提交于 2019-12-05 08:13:30
Okay, so I've created a directive let's say <calendar></calendar> It gets rendered as I expected so everything works fine. Now, my question is how to (re)render it when inserted into DOM? I don't want to use it on my page all the time, I just want to dynamically add it and render just when I need it to (it's a part of a module), let's say, ideally I want it to appear like $("body").append("<calendar></calendar>") How can I achieve this with angularjs? You need to write below two lines wherever you want to inject your directive element to DOM, don't forget to add $document & $compile dependency

Attribute without value in AngularJS directive

我与影子孤独终老i 提交于 2019-12-05 08:13:07
I've written a directive with an isolate scope. app.directive('myDirective', function() { return { restrict: 'E', scope { attr1: '@', attr2: '@', noValueAttr: // what to put here? }, link: function(scope, elem, attrs) { // how to check here if noValueAttr is present in mark-up? } }; }); the html could be <my-directive attr1='...' attr='...' ... no-value-attr> or <my-directive attr1='...' attr='...' > I am wondering how to use (and have the directive detect if it's there or not) an optional attribute which has no assigned value. Thanks. Just use attrs.hasOwnProperty('noValueAttr') in the link

Set validity of multiple inputs from a AngularJS Directive

霸气de小男生 提交于 2019-12-05 07:59:54
I'm trying to create a directive which can be used to reset validation status of multiple input controls in a group, when one of the control's value is changed. Groups are identified by the attribute of the directive set in HTML. Ex: - Both of the From Date and To Date inputs resets the validity state when one of the controls input value is changed by the user This is what I have so far JS/Angular angular.module('myModule').directive('groupedInputs', function () { return { restrict: 'A', require: '?ngModel', link: function (scope, element, attrs, ctrl) { element.on('change', function () { //

angularjs two directives on one element

假装没事ソ 提交于 2019-12-05 07:52:57
I have two directives: // Generated by CoffeeScript 1.6.3 app.directive("focusMe", function() { return { scope: { focus: "=focusMe" }, link: function(scope, element) { return scope.$watch("focus", function(value) { if (value === true) { element[0].focus(); return scope.focus = false; } }); } }; }); and: // Generated by CoffeeScript 1.6.3 app.directive("cleanMe", function() { return { scope: { clean: "=cleanMe" }, link: function(scope, element) { return scope.$watch("clean", function(value) { if (value === true) { element[0].value = ""; return scope.clean = false; } }); } }; }); and this input

Angular File Upload directive not updating controller model

拈花ヽ惹草 提交于 2019-12-05 07:46:25
I am attempting to follow this [tutorial] but can't get it working. My Angular controller is logging undefined for a model created in my directive. Here is a [JSFiddle] of it working created my author of tutorial. The problem is the view can find $scope.myFile and but controller does not ( $scope.myFile is undefined ). The view displays {{ myFile.name }} (as just example my-image.jpg ). The myFile variable is a JS object containing data on selected file. This works fine. The directive seems to be assigning the model the value of selected file (and thus displays it correctly in view). <input

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() { // ... }; } }

ui.bootstrap deforms the <progress> HTML tag

喜夏-厌秋 提交于 2019-12-05 06:08:37
In my HTML file I have a <progress> tag and I also injected the ui.bootstrap dependency to my controller as follows: var myApp = angular.module("myApp",["ui.bootstrap"]); In this configuration, AngularJS converts the <progress></progress> into: <div class="progress ng-isolate-scope" ng-transclude=""></div> When I remove "ui.bootstrap" it works fine. You can play out with this sample JSFiddle. When progress turned into <div class="progress ng-isolate-scope" ng-transclude=""></div> it disappears. I understand that there is a directive called progress in ui.bootstrap that makes this conversion.

Angularjs adding dynamically form fields in various forms

烂漫一生 提交于 2019-12-05 06:05:21
Using ng-repeat I am creating bunch of forms with values in it. With each form there is also button to add rows to that particular form with new fields. Code is below HTML: <form name="{{form.name}}" ng-repeat="form in forms"> <h2>{{form.name}}</h2> <div ng-repeat="cont in form.contacts"> <input type="text" class="xdTextBox" ng-model="cont.ac"/> <input type="text" class="xdTextBox" ng-model="cont.a_number"/> <input type="text" class="xdTextBox" ng-model="cont.p_id"/> </div> <button ng-click="submit(form)">Submit</button> <button ng-click="addFields(form)">Add</button> <hr> </form> Javascript: