angularjs-directive

AngularJS Directive for twitter bootstrap form-group

风流意气都作罢 提交于 2019-12-03 16:16:02
I've been playing with angular lately, so far so good, but im struggling with directives. I'm trying to create a directive that generates the html mark up for a standard bootstrap form group with its corresponding validation messages. So basically I'm trying to convert this: <form-group label="Password"> <input type="password" data-ng-model="vm.password" name="password" id="password" class="form-control form-control-validate" required data-ng-minlength="6" data-required-error="Password is required" data-minlength-error="Your password must have at least 6 characters" /> </form-group> into this:

AngularJS directive test fails - Why “element” has the a wrong value?

ぐ巨炮叔叔 提交于 2019-12-03 16:12:02
Given the following directive, could one explain why the following test fails? DEMO DIRECTIVE angular.module('plunker').directive('maybeLink', function($compile) { return { scope: { maybeLink: '=', maybeLinkText: '=' }, link: function(scope, element, attrs) { scope.$watch('maybeLinkText', function(newVal) { scope.text = newVal.replace(/\n/g, '<br>'); }); scope.$watch('maybeLink',function() { var newEl; if (scope.maybeLink) { newEl = $compile('<a href="#">{{ text }}</a>')(scope); } else { newEl = $compile('<span>{{ text }}</span>')(scope); } element.replaceWith(newEl); element = newEl; }); } };

How to test a directive's controller using angularJS-karma-jasmine?

百般思念 提交于 2019-12-03 16:00:40
Goal: Write a passing test for the waCarousel directive scope variable: self.awesomeThings . Expect this test pass when self.awsomeThings.length.toBe(3) to is true? Question: How can I properly write this test? rather how do I inject a directives controller? Directive: angular.module('carouselApp') .directive('waCarousel', function() { return { templateUrl: '../../../views/carousel/wa.carousel.html', controller: function($scope) { var self = this; self.awesomeThings = [1, 2, 3]; return $scope.carousel = self; } } }); Unit Test: describe('waCarousel Unit', function() { // am I missing a

Issue with isolated scope and “replace: true” in angular directive

为君一笑 提交于 2019-12-03 15:30:40
I have been struggling with a scoping issue when making an error message directive using AngularJS. I have an ng-if and ng-class directive as part of the directive template, but the expression in the ng-class directive always seemed to return a blank string, unless: I removed the ng-if directive. or, I removed the 'replace' key in the directive definition object. Looking at the compiled output for my directive, it looks like an isolated scope is being created if the ng-if or the replace key is removed, but if they are both left in, then there are no ng-isolate-scope classes in the html output,

Angular modal dialog best practices

荒凉一梦 提交于 2019-12-03 14:53:54
What is the best practice for creating modal dialogs with dynamic content, contrasted with dialogs that don't have dynamic content. Eg.. We have some modal forms that accept a list of form elements, and have submit/cancel. Also, there are modal dialogs that just display a confirm/ok type of operation. I've seen a lot of people saying that dialogs should be services passed into the controller, but it seems to me that services shouldn't be rendering UI components and manipulating the DOM. What is the best practice for assembling these two types of dialogs? Thanks. Angular UI Boostrap provides a

How to asynchronously load a google map in AngularJS?

谁都会走 提交于 2019-12-03 14:45:16
问题 Now that I have found a way to initialize Google Maps with the help of Andy Joslin in this SO initialize-google-map-in-angularjs, I am looking for a way to asynchronous load a Google Map Object. I found an example of how to do this in the phonecat project. Notice how the JS files are loaded in this example: index-async.html In my Jade Scripts partial that is loaded into my program I tried: script(src='js/lib/angular/angular.js') script(src='js/lib/script/script.min.js') script $script([ 'js

Isolate Scope “=” binding and doted notation AngularJS

馋奶兔 提交于 2019-12-03 14:33:44
How do you create a 2 way binding with a nested property in an isolate scope with dotted notation. I thought 'myObject.data': "=data" would work, but it does not. I don't want to link everything in the myObject object. I know I could do some sort of watch, but 'myObject.data' seems cleaner. .directive("myDirective", [function() { return { restrict: "E", scope: { 'myObject.data': "=data" }, link: function (scope, element, attrs) { scope.myObject = { data: "myValue" }; } }; }]) Isolated scopes are generally useful only with templates, they should not be used as a way to declare how you want your

How do I capture table td elements using mousedown.dragselect event?

你说的曾经没有我的故事 提交于 2019-12-03 13:54:41
I have a directive which renders a HTML table where each td element has an id What I want to accomplish is to use the mousedown.dragselect/mouseup.dragselect to determine which elements have been selected, and then highlight those selected elements. What I have so far is something like this: var $ele = $(this); scope.bindMultipleSelection = function() { element.bind('mousedown.dragselect', function() { $document.bind('mousemove.dragselect', scope.mousemove); $document.bind('mouseup.dragselect', scope.mouseup); }); }; scope.bindMultipleSelection(); scope.mousemove = function(e) { scope

AngularJS directive is not working

大城市里の小女人 提交于 2019-12-03 13:53:26
Please find below the directive which i wrote, angular.module('netVogue.directives', []). directive('set-First-Active', function() { return function(scope, element, attrs){ alert('sample'); element.addClass("active"); }; }); I have added this directive to my module in below way, angular.module('netVogue', ['netVogue.filters', 'netVogue.services', 'netVogue.directives']); I used this directive in my template in following format, <div class="item" ng-repeat="viewPrintcampaign in viewPrintcampaigns" ng-init="first=$first" set-First-Active> </div> However, i neither see any response of alert nor

How do you use dynamic ng-show values inside a directive template?

不打扰是莪最后的温柔 提交于 2019-12-03 13:50:45
问题 I am learning angular, and I am trying to reduce some code that it takes to do some common things, like display error messages, by using angular directives. One directive I would like to create is like this: <error-message name="paymentPlanForm.position" error="required"> This field is required. </error-message> This would generate the following: <p ng-show="paymentPlanForm.position.$dirty && paymentPlanForm.position.$error.required"> <span class="fontawesome-remove"></span> This field is