angularjs-directive

Angular JS and Complex Directives

二次信任 提交于 2019-12-06 14:22:33
问题 This is an AngularJS widget which replaces a tag with an editable text field. Clicking the text replaces it with an input field, and hitting enter on the input updates an existing resource. I am not happy with the code I produced. Are all of these evals and applys really necessary? How can I improve this? To use editable-text(model="activeCustomer.phone_number", resource="Customer", field="phone_number") The Directive Code .directive("editableText", function($injector){ return { restrict: "E"

Angularjs Button loading state directive with ng-disabled directive

故事扮演 提交于 2019-12-06 13:35:53
问题 I am trying to reconcile using the following directive for changing a button's loading state via bootstrap js plugin: .directive("btnLoading", function() { return function(scope, element, attrs) { scope.$watch(function() { return scope.$eval(attrs.btnLoading); }, function(loading) { if (loading) return element.button("loading"); element.button("reset"); }); }; This is working quite well as it controls the state of the button when necessary and adds the loading text as advertised. The issue I

Why is angular.js not smart enough to compile DOM when adding dynamic elements?

僤鯓⒐⒋嵵緔 提交于 2019-12-06 13:12:50
I really like how AngularJS enables custom tags/elements by allowing you to declare directives inside your app, however, when I append a custom tag dynamically, nothing happens: angular.module('myApp', []).directive('test', (($compile) -> restrict: 'E' link: (scope, element, attributes) -> $(element).html('<h1>this is a test!</h1>') )) $('body').append('<test></test>') How can I build an instance of my custom tag dynamically? Why are you calling jquery outside of angular? Normally you would do something from inside an angular directive for instance and that would have access to $compile. If

AngularJS - Add computation value from a function to the scope

梦想与她 提交于 2019-12-06 13:04:30
I have two datepicker fields which is implemented using AngularStrap datepicker directives: http://mgcrea.github.io/angular-strap/ . <input type="text" name="startDate" ng-model="startDate" data-date-format="dd/mm/yyyy" placeholder="DD/MM/YYYY" bs-datepicker /> <button type="button" class="btn" data-toggle="datepicker"> <i class="icon-calendar"></i> </button> <input type="text" name="endDate" ng-model="endDate" data-date-format="dd/mm/yyyy" placeholder="DD/MM/YYYY" bs-datepicker /> <button type="button" class="btn" data-toggle="datepicker"> <i class="icon-calendar"></i> </button> I also have a

Directive for lazyloading data in AngularJS

柔情痞子 提交于 2019-12-06 12:45:50
问题 I'm currently learning Angular and trying to figure out a good pattern for lazyloading data and structuring code. I'm making an responsive web application, and I would like do be able to define that some parts of the web-page are to be hidden from the view (preferably using media queries). The data fetched for the hidden directives or views is then redundant. The difference can be substantial from a desktop to a mobile view, and I would like the application to be as light as possible on the

ngSticky plugin not working when the sticky directive is used inside of a template

与世无争的帅哥 提交于 2019-12-06 12:41:20
问题 I'm using the Ionic framework and was looking for a non-jquery sticky menu plugin, when I found ngSticky . bower install ngSticky Great plugin, the demo file included shows it working great, just add the sticky attribute to whatever div you want stickfied. Problem is, for some reason it's not working inside of my <ion-nav-view> <ion-content> part of the Ionic framework . Here is my demo link: http://leongaban.com/sticky/#/ When you scroll down, the gray header bar should stick. It does stick

How to dynamically add a directive to all input elements in AngularJS across controllers & modules

。_饼干妹妹 提交于 2019-12-06 12:27:12
问题 I want to add a directive dynamically to all my textboxes in all my controllers & forms. I got a hack from here : How to dynamically add a directive to an input element in AngularJS but in my case: there are around 200+ forms spread across different controllers & modules & it will be very time consuming to add it everywhere. Is there an easier or more elegant way to do it ? Edit: What I want to do ? I want to remove all leading & trailing spaces entered by user in all input boxes. 回答1:

Getting angular directive attribute value returns 'undefined'

纵然是瞬间 提交于 2019-12-06 12:04:06
I'm doing a directive for input mask. But, when I pass a string as value the attribute is undefined. If I pass directly the mask It's working. .directive('inputMask', function () { return { restrict: 'EAC', scope: true, link: function (scope, element, attrs) { scope.$watch('inputMask', function (newVal) { console.log('inputMask', newVal); }); var maskType = scope.$eval(attrs.inputMask); switch (maskType) { case 'phone': $(element).inputmask("phone", { url: '@Url.Content("~/Scripts/jquery-inputmask/phone-codes/phone-codes.json")', onKeyValidation: function () { //show some metadata in the

Angular JS : Insert one directive into another directive dynamically

跟風遠走 提交于 2019-12-06 11:45:45
First of all, the way i am doing may not be correct. But i will explain the problem: 1) I am creating directive called as < firstDirective > 2) when the clicks on a button in the first directive, then I am trying to insert the second directive dynamically at runtime As follows: <!DOCTYPE html> <html> <script src="lib/angular/angular.js"></script> <body ng-app="myApp"> <first-directive></first-directive> <script> var app = angular.module("myApp", []); app.directive("firstDirective", function() { return { template : '<h1>This is first directive!</h1> <br / ><br / ><button type="button" ng-click=

AngularJs - Calling controller function from directive

天大地大妈咪最大 提交于 2019-12-06 11:43:47
问题 In an angularjs project I am using a directive to upload files by drag/dropping them in a dropzone. In the directive I need to call a function that is defined within my controller. Here is what I am doing: (function () { 'use strict'; angular .module('app') .controller('myController', myController) .directive('fileDropzone', function () { return { restrict: 'A', scope: { file: '=', fileName: '=', test: '&callbackFn', }, link: function (scope, element, attrs) { var processDragOverOrEnter;