angularjs-directive

How to test directives that use templateUrl and controllers?

我的未来我决定 提交于 2019-12-03 09:06:22
EDIT: after asking the question, i'm now editing this to elaborate on my findings. My app is modularized using directives. I'm writing my directives such that they (1) create their own scope (2) use templateUrl, and (3) do most of the logic and server data fetching in their controller. The question is how to unit test it, using Mocha with Karma. Lior a test is written for each directive. Since the directive uses templateUrl, I used html2js. the html key should be included as a module - that puts the template into the templateCache. Then, I compiled the directive, and run the link function with

AngularJS - what are the major differences in the different ways to declare a service in angular?

末鹿安然 提交于 2019-12-03 08:47:25
I am working on an angularJS app and I am trying to stick with the most efficient and widely accepted styles of development in AngularJs. Currently, I am using this way of declaring my services like so: app.factory('MyService', function() { /* ... */ function doSomething(){ console.log('I just did something'); } function iAmNotVisible(){ console.log('I am not accessible from the outside'); } /* ... */ return{ doSomething: doSomething }; }); However, there are numerous examples out there and I am not quite sure which design style to follow. Can someone with extensive knowledge about services

Directives isolated scope not working properly together with nested views? (AngularJS / UI Router)

£可爱£侵袭症+ 提交于 2019-12-03 08:45:54
I'm using ui-router in a AngularJS project where I have a nested view that contains a custom directive. This directive renders an input field (lets say a filter-field) and its value should be in sync with the controller's scope. This works well for this directive, when the view/state not is nested: jsFiddle / not nested / working as expected var myApp = angular.module('myApp', ['ui.router', 'myComponents']) .config(['$stateProvider', function ($stateProvider) { $stateProvider. state('home', { url: '', template: '<my-filter text-filter="theFilter"></my-filter><button ng-click="inspect()"

How to use <head> tag with Angular directive

你说的曾经没有我的故事 提交于 2019-12-03 08:42:08
I tried this in my Angular app, but it does not work. So I tried inserting a custom tag( <mytag> ) into the head and made the directive work with this by replacing "head" with "mytag". This however is not really what I intended, because it adds <mytag> to the body instead of the <head> Does anyone know how to make it work with the head-tag? I had the same challenge. Make sure that your angular app is initialized on the html tag. Then this solution works out of the box. However for us this was not an ideal solution. So I modified Zack Boman (tennisgent) https://github.com/tennisgent/angular

AngularJS Multiple Directive Resource Contention

牧云@^-^@ 提交于 2019-12-03 08:30:23
I am trying to build a directive with angular. Here is the plunker I wanted to split it into 3 directives: Top, grand-parent directive. - many DAYS Middle, created with ng-repeat - one DAY Bottom, created with ng-repeat - many TIME BLOCKS angular .directive('dateTimeBlocks', [function dateTimeBlocksDirective () {}]) .directive('dayBlock', [function dayDirective () {}]) .directive('timeBlock', [function timeBlockDirective () {}]) I wanted to create middle and bottom directives with isolated scopes and only pass the data that I want to modify inside. But it seems to unable to compile "Multiple

AngularJS: Best way to watch dimensions?

徘徊边缘 提交于 2019-12-03 08:29:40
问题 So, I've come up with a few solutions to this and I'm still not quite sure what is best. First for reference there is one similar question I could find, though it's a bit old. Here it is for anyone reading this later: Watching dimension changes in Angular The Goal I have portions of my app in which responsive height elements are needed. I want the fastest, most visually appealing way to do this at the UI/directive layer without the need of explicitly broadcasted change events. Option One:

How to pass a function reference in a recursive directive in Angular?

廉价感情. 提交于 2019-12-03 08:19:52
I have this directive: app.directive('recursiveListItem', ['$http', 'RecursionHelper', function ($http, RecursionHelper) { return { restrict: 'E', scope: { parent: '=', onNodeClick: '&', }, compile: function (element, attributes) { return RecursionHelper.compile(element); }, template: '<div class="list-group-item-heading text-muted parent "> \ <input type="checkbox" data-ng-click="visible = !visible" id="{{parent.Name}}">\ <label for="{{parent.Name}}">  </label>\ <a href="javascript:void(0)" data-ng-click="onNodeClick({node: parent})">{{parent.Name}}</a> \ </div> \ <ul data-ng-if="parent

Angular.js - controller function to filter invalid chars from input does not delete chars until a valid char is entered

China☆狼群 提交于 2019-12-03 08:16:27
I have created a JSFiddle of the issue I am experiencing here: http://jsfiddle.net/9qxFK/4/ I have an input field that I want to only permit lower case letters, numbers, and hyphens (this field will be used in a URL). I have the following angular.js controller method in order to do this: $scope.auto_slug = function() { $scope.slug = $scope.slug.toLowerCase().replace(/[^a-z0-9\-\s]/g, '').replace(/\s+/g, '-'); }; Invalid characters are only being removed when a valid character is typed after an invalid character. Can anybody tell me why this doesn't work? Thanks, Scott Instead of doing that on

How to create an angularJs wrapper directive for a ui-bootstrap datepicker?

爱⌒轻易说出口 提交于 2019-12-03 08:04:30
问题 I am using the ui.bootstrap.datepicker directive to display some date field. However most of the time I need the same setup: I want it to come along with a popup and a popup button and also I want German names for the texts. That does create the same code for the button and the texts and the formatting over and over again, so I wrote my own directive to prevent myself from repeating myself. Here is a plunkr with my directive. However I seem to be doing it wrong. If you choose a date with the

Exporting ng-grid data to CSV and PDF format in angularjs

允我心安 提交于 2019-12-03 07:56:48
问题 Please Help me....any plugin is there..? I have searched for exporing excel and PDF in angularjs. using ng-grid. Exporting ng-grid data to CSV and PDF format in angularjs 回答1: For csv export there is the ngGridCsvExportPlugin that you can find here Just at a reference to the script and add the ngGridCsvExportPlugin to the gridOptions (and activate the footer too by adding showFooter : true to the gridOption) $scope.gridOptions = { data: 'myData', plugins: [new ngGridCsvExportPlugin()],