angularjs-directive

Angular directive's link function not being called

北城以北 提交于 2019-12-11 09:47:35
问题 I've got a problem with AngularJS directive link function. It's not beeing called and it doesn't throw any error. Also the template in directive's return is not rendering :( Where should be problem? Thank you for answers! angular.module('sampleApp.game').directive('gameCanvas', function($injector) { console.log('Directive is working'); // this works, function linkFn(scope, ele, attrs) { console.log('Link function doesnt working :('); // but this not :( }; return { scope: {}, template: '<div

Detect if directive was removed from DOM

删除回忆录丶 提交于 2019-12-11 09:27:32
问题 I have an AngularJS directive and I need to perform certain actions if the directive's element is removed from the DOM (either from inside an AngularJS call or by any other method, like jQuery). Is that possible? 回答1: In the directive, when an element is removed from DOM, $destroy event is emitted. Inside your directive's link function, you can do this:- element.on('$destroy', function() { // do stuff }); For more information and complete example, see documentation here EDIT: See this plunker

AngularJS - Ordering and Parsing data in a ng-repeat, based on a parent ng-repeat

若如初见. 提交于 2019-12-11 09:27:32
问题 Im trying to write a fairly complex ng-repeat that potentially uses filtering and parseing. What i am first doing is ng-repeat ing a table heading of 12 months from the current month. I am then displaying two rows - Searches with impact and Searches with NO impact What i am trying to do is loop through my JSON file that contains my search data, and counts how many Searches with Impact and Search with No Impact , have been carried out for that particular month based on the SearchedOn field.

Enter animation not playing in Angular

谁都会走 提交于 2019-12-11 09:27:15
问题 I'm wondering how could I animate an element when the angular app is starting. Indeed, I see (I'm maybe doing something wrong) that the animation module is not triggering the "enter" event the first time, but after everything goes fine. How could I animate it without rewriting all the code I have in my animation module somewhere else ? You can see on my fiddle that the li is green at first glance, when I need it to be blue as defined in my enter animation. I don't know if it only occurs in my

Angular - two-way binding through an ng-switch

≡放荡痞女 提交于 2019-12-11 09:19:57
问题 I have a directive with scope and a two-way '=' binding to a parent-scope value (yes, inside an object to avoid inheritance problems.) The directive's template in turn contains an ng-switch, which of course creates another scope. Inside the ng-switch I want to have a textarea bound to the original value. It gets initialized correctly, but when the user edits the value, the parent scope value doesn't change. var myApp = angular.module('myApp', []); myApp.directive('csContenteditable', function

When to get the width of an Angular directive?

人走茶凉 提交于 2019-12-11 09:19:47
问题 When and how can I get the length of a to-be-compiled div in Controller and/or Directive , the .length-wanted in this case, without resorting to $timeout ? Or is there an event telling me that Angular's work is all done and I could go get its height/width? <div ng-controller="testCtrl"> <div get-length> <div class="length-wanted" ng-bind="arr"></div> </div> </div> Demo here: http://jsfiddle.net/luxiyalu/tm54k4je/ 回答1: Since it's possible that its size might change with resize, I eventually

AngularJS - dynamically load templateURL when passing object into attribute

↘锁芯ラ 提交于 2019-12-11 09:14:47
问题 In my controller HTML I am passing an object into a directive as such: <div cr-count-summary countdata="vm.currentCountData"></div> The vm.currentCountData is an object that is returned from a factory My directive code is below: function countSummary() { var directive = { scope: { countData: '=' }, link: link, templateUrl: function(element, attrs) { if (attrs.countdata.type === 'Deposit') { return 'app/count/countsummary/countDeposit.html'; } else { return 'app/count/countsummary

How to Properly use the ng-model Directive and its Controller in Custom Directives?

馋奶兔 提交于 2019-12-11 09:13:04
问题 I've created a directive which wraps jstree and I used ng-model inside my custom directive tag to pass some json data. My question is : Do I have to use ng-model in this case ? 回答1: I've created a directive which wraps jstree and I used ng-model inside my custom directive tag to pass some json data. Do I have to use ng-model in this case ? The ng-model directive instantiates the ngModelController. It is a complex directive that enables form validation and is the prerequisite for the ng-change

How to $compile angular template to make it work in multiple controllers with aliases?

一曲冷凌霜 提交于 2019-12-11 08:55:13
问题 I have a custom directive that simply $compiles a template into another. .directive('staticInclude', function($http, $templateCache, $compile) { return function(scope, element, attrs) { var templatePath = attrs.staticInclude; // $http.get(templatePath, { cache: $templateCache }).success(function(response) { var contents = element.html(response).contents(); $compile(contents)(scope); }); }; }); I use it like: <div static-include="components/campaign/details.html"></div> Because I'm using

Binding to events in a directive which is inside a ng-view doesn't work

為{幸葍}努か 提交于 2019-12-11 08:53:03
问题 I have an AngularJS application, which hasn't been using the built in routing before now. I am refactoring the site, so it will be a SPA. To do this I have change the app to use ng-view to switch between the different pages, instead of just having the server serve the different controllers After this is done my endless scroll suddenly stopped working. I have a directive which looks like this: directiveModule.directive('whenScrolled', ['$window', function($window) { return function(scope,