angularjs-directive

AngularJS - Use attribute directive conditionally

蹲街弑〆低调 提交于 2019-12-18 10:20:45
问题 I am using "draggable" directive to support image dragging. However, as per the role of the user, I need to disable image dragging for certain groups of users. I have used following code. <!--draggable attribute is used as handle to make it draggable using jquery event--> <li ng-repeat="template in templates" draggable id="{{template._id}}" type="template" class="template-box"> <!-- Images and other fields are child of "li" tag which can be dragged.--> </li> The method dragSupported is in the

AngularJS - how to change the value of ngModel in custom directive?

巧了我就是萌 提交于 2019-12-18 10:13:38
问题 Lets take a look to my directive: angular.module('main').directive('datepicker', [ function() { return { require: '?ngModel', link: function(scope, element, attributes, ngModel) { ngModel.$modelValue = 'abc'; // this does not work // how do I change the value of the model? So, how do I change the value of the ng-model? 回答1: There are different ways of doing it: $setViewValue() updates the view and the model. Most cases it is enough. If you want to disconnect view from the model (e.g. model is

Directive template unique IDs for elements in AngularJS

混江龙づ霸主 提交于 2019-12-18 10:10:39
问题 I have a directive that can be used multiple times on a page. In the template of this directive, I need to use IDs for an input-Element so I can "bind" a Label to it like so: <input type="checkbox" id="item1" /><label for="item1">open</label> Now the problem is, as soon as my directive is included multiple times, the ID "item1" is not unique anymore and the label doesn't work correctly (it should check/uncheck the checkbox when clicked). How is this problem fixed? Is there a way to assign a

directive not interpolating, in a template string

故事扮演 提交于 2019-12-18 08:45:49
问题 I'm trying to conditionally build a template. I got a k2plugin directive with some divs and spans. According to the pluginui attribute, I want to insert another directive at the end of the template. My code, that follows, interpolates everything but pluginui For example, the last div results in: <div {{pluginui}} width='300' height='420'></div> {{pluginui}} is literal, while it should interpolate to trigger the other directive. Funny thing is, if I put {{pluginui}} elsewhere in the same line

directive not interpolating, in a template string

不问归期 提交于 2019-12-18 08:45:43
问题 I'm trying to conditionally build a template. I got a k2plugin directive with some divs and spans. According to the pluginui attribute, I want to insert another directive at the end of the template. My code, that follows, interpolates everything but pluginui For example, the last div results in: <div {{pluginui}} width='300' height='420'></div> {{pluginui}} is literal, while it should interpolate to trigger the other directive. Funny thing is, if I put {{pluginui}} elsewhere in the same line

angular dynamic templating directives

*爱你&永不变心* 提交于 2019-12-18 07:14:27
问题 I have a list of different field types and I want to apply a template based on type. I can get it to work if I use inline templates like this: flowPageModule.directive('myField', ['$compile','$http', '$templateCache', function($compile, $http, $templateCache) { var inlineTemplateMapping = { select: '<div><span> {{label}} &nbsp <select ng-model="metadata.options[0]" ng-options="o.text for o in metadata.options"></select> </span></div>', text: '<div><span> {{label}} &nbsp <input type="text" />

Angularjs dynamically adding and removing elements using directive

旧时模样 提交于 2019-12-18 07:07:01
问题 I used directive for creating contact form. Initially i create customerForm directive for displaying customer form. In that form i have one button, when we click on add button, called getData function and that function internally used newDirective for displaying ul list. for that i used $compile api for compiling html code. that is fine and its also display list value and remove button when we click on remove button, its called scope.remove() function. But its delete only ones. after that i

Directives inside ng-include

橙三吉。 提交于 2019-12-18 05:55:44
问题 I'm building a simple angularjs app and I'm trying to implement login without page refresh. What I'm doing On init the ng-include loads the /set/save. The /set/save got the <a fblogin>Login with Facebook</a> in it. So when clicked the directive opens a window and when the window is closed it should change the src of the ng-include. The problem When the directive is used inside the ng-include ( ng-include src has default value on init ), nothing happens ( no errors in console, just nothing ),

AngularJS Google Map directive map instance

微笑、不失礼 提交于 2019-12-18 05:53:57
问题 I'm using http://angular-google-maps.org/ it's nice angular google maps library. But i want use map instance which is loaded not in angularjs context by something like this: $scope.map = { events: { tilesloaded: function (map) { $scope.$apply(function () { $scope.mapInstance = map; }); } } } Ok nice i have mapInstance and I CAN use it programmatically. But in application lifecycle this fire to late- so in other words I want to load whole directive (and get map instance) before other code-

How to disable a <option> of select element when using AngularJS ng-options?

柔情痞子 提交于 2019-12-18 05:52:27
问题 Is there a way to disable an option in a select element when we populate options with ng-options in AngularJS? Like this: http://www.w3schools.com/tags/att_option_disabled.asp You can do it by adding ng-disabled to each <option> tag, but is there a way to do it if we are using the ng-options directive in the select tag? 回答1: One way to do this is, to forget using ng-options on the select element, and add the options in with ng-repeat , then you can add a ng-disabled check on each option .