angularjs-directive

Is there a way to get the raw DOM element from an angular.element

孤街醉人 提交于 2019-12-03 06:11:29
问题 angular.element All element references in Angular are always wrapped with jQuery or jqLite; they are never raw DOM references. How can I get the raw DOM element, because I have legacy JS code (jscolor Picker) that needs the raw DOM element? 回答1: Found it: ang_element = angular.element(element); raw_element = ang_element[0]; 来源: https://stackoverflow.com/questions/18302493/is-there-a-way-to-get-the-raw-dom-element-from-an-angular-element

AngularJS element.innerHTML is undefined from within directive

女生的网名这么多〃 提交于 2019-12-03 06:10:22
Let's say I have: directives.directive('foo', function () { return { restrict:'A', scope: true, link:function (scope, element, attr) { console.log('innerHTML is ' + element.innerHTML); scope.$watch('update', function (newValue) { console.log('innerHTML is... ' + element.innerHTML); }); } } }); ... then innerHTML is undefined. I imagine this is due to the way Angular processes the DOM. What is the right way to obtain the innerHTML? The element variable that is passed to your link function is a jqLite object - not a DOM object. You can obtain the DOM object with element[0] (like you could in

AngularJS directives - best practices when using ngModel with jQuery widget

给你一囗甜甜゛ 提交于 2019-12-03 06:01:37
Here is my problem. For example, we have the following directive, which uses some jQuery widget behind the scenes : module.directive('myWidget', [function() { return { require: "ngModel", restrict: "A", replace: true, templateUrl: "templates/myWidget.html", link: function(scope, element, attrs, ctrl) { element.widget_name().on('value_updated', function(event) { scope.$apply(function() { var newModelValue = event.some_value; ctrl.$setViewValue(newModelValue); }); }); scope.$watch(attrs["ngModel"], function(value){ element.widget_name('set_value', value); }); } }; }]); So, if model's value

Modifying DOM (slideDown/slideUp) with AngularJS and jQuery

心已入冬 提交于 2019-12-03 05:47:13
问题 I'm trying to implement a slideDown/slideUp animation with AngularJS. I can't use CSS3's transition (unfortunately) since the height is set to auto (and I don't want to use the max-height workaround), so I'm trying to use jQuery's slideToggle method. Given the following markup: <ul> <li ng-repeat="entry in data"> <span>{{entry.title}}</span> <a ng-click="clicked($event)" href>more?</a> <p>{{entry.description}}</p> </li> </ul> I implemented the following method in my controller: $scope.clicked

AngularJS : transcluding multiple sub elements in a single Angular directive

我只是一个虾纸丫 提交于 2019-12-03 05:30:08
问题 I am Fairly new to Angular but have been reading quite a lot. I was reading about ng-transclude at http://docs.angularjs.org/guide/directive#creating-custom-directives_demo_isolating-the-scope-of-a-directive and I think I understand properly what it does. If you have a directive that applies to an element that has content inside it such as in <my-directive>directive content</my-directive> It will allow you to tag an element within the directive's template with ng-transclude and the content

Change Angular directive element attribute dynamically

柔情痞子 提交于 2019-12-03 05:21:35
问题 I am trying to create a custom directive which extends the functionality of an existing element. I would like to detect if a certain attribute exists and if not then add it (e.g. ng-class). I have tried to achieve this during pre-compilation but angular does not react to the addition of the new attribute. I created a plunker with a simple example using ng-hide. <input hide type="submit" value="Submit"/> app.directive('hide', function() { return { restrict: 'A', compile: function(){ return {

AngularJS : ng-controller on directive does not work on transcluded elements within directive

只谈情不闲聊 提交于 2019-12-03 05:13:29
问题 Here is my script: angular.module('MyApp',[]) .directive('mySalutation',function(){ return { restrict:'E', scope:true, replace:true, transclude:true, template:'<div>Hello<div ng-transclude></div></div>', link:function($scope,$element,$attrs){ } }; }) .controller('SalutationController',['$scope',function($scope){ $scope.target = "StackOverflow"; }]) and the html: <body ng-app="MyApp"> <my-salutation ng-controller="SalutationController"> <strong>{{target}}</strong> </my-salutation> </body> The

Template must have exactly one root element with custom directive replace: true

被刻印的时光 ゝ 提交于 2019-12-03 05:11:53
问题 I am having issues with a custom directive with replace: true, http://jsbin.com/OtARocO/2/edit As far as I can tell, I do only have one root element, my , what is going on here? Error: Template must have exactly one root element. was: <tbody> <tr><td>{{ item.name }}</td></tr> <tr><td>row2</td></tr> </tbody> Javascript: var app = angular.module("AngularApp", []) .directive('custom', [function () { return { restrict: 'E', replace: true, templateUrl: 'lineItem.html', link: function(scope,

AngularJS Directive: How do I hide the alert using timeout?

折月煮酒 提交于 2019-12-03 05:11:17
问题 Yesterday, I started writing a notification directive for my project I asked question on stackoverflow AngularJS: Alerts not showing up and after struggling through documents and videos, I am able to build a basic notification directive http://plnkr.co/edit/uqSB1gIz6XEmJfC8zHNb?p=preview What I want? Like any other app, when alerts show up, they hide after a second or so, I am trying to find out a way to hide the alert after a second, but not sure how to do that Any help is greatly

add watch on a non scope variable in angularjs

有些话、适合烂在心里 提交于 2019-12-03 04:58:11
问题 Is there a way to add watch to a non scope variable. I want to add a watch to local variable. I have something like this function EditAssetRegistryController(assetregistryService, manufacturerService, assettypeService, projectService, $localStorage, $routeParams) { var vm = this; vm.manufacturers = []; vm.projects = []; vm.asset_types = []; vm.ch_group_uniq = 'none'; } here is there a way to add watch to vm.ch_group_uniq? I know how it will be done with scope variable but I have scenarios