angularjs-directive

AngularJS/UI Bootstrap - fading out alert on remove

ⅰ亾dé卋堺 提交于 2019-12-18 13:19:52
问题 I am using Angular with UI Bootstrap. I've created the custom directive that pushes broadcasted alerst into the array of alerts that are bound to the view (rendered as Bootstrap alerts). After the certain timeout the alerts get removed from the array (and hence from the view). Here is the code: angular.module('myApp') .directive('alerts', function ($timeout) { return { restrict: 'E', templateUrl: 'views/alerts.html', scope: true, /*share scope between alerts directives*/ link: function (scope

Dynamic ng-model binding inside a directive

橙三吉。 提交于 2019-12-18 12:57:06
问题 I'm trying to create a custom component that uses a dynamic ng-model inside-out the directive. As an example, I could invoke different components like: <custom-dir ng-model="domainModel1"></custom-dir> <custom-dir ng-model="domainModel2"></custom-dir> With a directive like: app.directive('customDir', function() { return { restrict: 'EA', require: '^ngModel', scope: { ngModel: '=dirValue', }, template: '<input ng-model="dirValue" />', link: function(scope, element, attrs, ctrl) { scope

What is the default for AngularJS directive scope?

回眸只為那壹抹淺笑 提交于 2019-12-18 12:56:16
问题 What is the default scope value of an AngularJS directive? Of course, it is not isolated scope. It is true or false. I can't find any documentation on what it is. 回答1: "Note, by default, directives do not create new scope -- i.e., the default is scope: false " from Understanding scopes. Using the scope option in directive you can: create a child scope prototypically inherited with scope: true create an isolated scope with scope: {} then you can bind some property to parent scopes with '@', '&

Angular.js How to update the scope from a directive?

梦想与她 提交于 2019-12-18 12:54:21
问题 How can I update scope in directive? <div ng-controller="MyCtrl"> <p t></p> </div> My directive: var myModule = angular.module('myModule', []) .directive('t', function () { return { template: '{{text}}', link: function (scope, element, attrs) { scope.text = '1'; element.click(function() { scope.text = '2'; }); } }; }) .controller('MyCtrl', ['$scope', function ($scope) { }]); After click directive does not update. 回答1: Use $apply method: element.click(function() { scope.$apply(function(){

How to set a native attribute from AngularJS directive?

ⅰ亾dé卋堺 提交于 2019-12-18 12:18:16
问题 I'd like to write HTML similar to: <a href="sharedasset: img.png">test</a> <img src="sharedasset: img.png"/> And have a directive called "sharedasset" that gets the full path to img.png and sets the value of the attribute without the directive having any knowledge of what the attribute name is ahead of time. Is this possible? Update Since I originally posted this there have been some improvements to Angular and I thought I'd share what I do now as a result. In the HTML I use Guido Bouman's

Angular Directive table rows issue

有些话、适合烂在心里 提交于 2019-12-18 12:15:23
问题 I am a beginner Angular programmer, but I am really close to understanding the directives. I create a fiddle here, but I have never used fiddle before, and it is not quite rendering ... the tr-row is a directive. I am trying to loop through the data, and print a directive (row) per record. HTML: <table ng-controller="fiddleCtrl"> <thead> <th>id</th> <th>name</th> <th>description</th> </thead> <tbody> <tr><tr-row ng-repeat="d in data" scdata="d"></tr-row></tr> </tbody> </table> javascript: var

AngularJS: Should I convert directive's linking function to a controller?

送分小仙女□ 提交于 2019-12-18 11:15:16
问题 I heard it's a good practice to use the controllerAs syntax along with bindToController: true in directives that use an isolate scope. References: one, two Suppose, I have a directive like this: angular.module('MyModule').directive('MyDirective', function(User) { return { scope: { name: '=' }, templateUrl: 'my-template.html', link: function(scope) { scope.User = User; scope.doSomething = function() { // Do something cool }; } }; }); <!-- my-template.html --> <div> User Id: {{ User.id }} Name:

AngularJS: Protecting routes with angularjs depending if the user is authorized?

ぐ巨炮叔叔 提交于 2019-12-18 10:55:32
问题 I have just started out working with an AngularJS app I'm developing, everything is going well but I need a way of protecting routes so that a user wouldn't be allowed to go to that route if not logged in. I understand the importance of protecting on the service side also and I will be taking care of this. I have found a number of ways of protecting the client, one seems to use the following $scope.$watch( function() { return $location.path(); }, function(newValue, oldValue) { if ($scope

AngularJS Form Validation Directive $setValidity on element

邮差的信 提交于 2019-12-18 10:23:00
问题 I'm trying to use $setValidity on an element in a directive. All the examples I've found seem to set it on the controller... I forked a JS fiddle on Form Validation and have tried a bunch of things. Any insights would be most appreciated: http://jsfiddle.net/thomporter/pmKpG/2/ In the fiddle, the $setValidity is called on the controller: ctrl.$setValidity('pwd', true); I'd like to do something like: elm.$setValidity('pwd', true); so that in the form I can do something like: ng-class="{error

Angular.js & Adsense

风流意气都作罢 提交于 2019-12-18 10:21:13
问题 I'm trying to put ads on my angular.js app, and I've done some reading and discovered it isn't possible to just copy and paste the normal adsense code. I've heard you are supposed to "wrap it in a directive with a transclusion," and the only example I can find of this is another Stackoverflow post: AngularJs and AddThis social plugin Can someone help give guidance about how to go about doing this with Google Adsense? 回答1: you need to create a directive yourApp.directive('ads', function() {