angularjs-directive

AngularJS - directive scope not setting ng-class on element

ぃ、小莉子 提交于 2019-12-08 07:08:58
问题 Plunker I have a table of data: <table class="table table-hover" ng-class="dndElemClass" drag-and-drop> ... </table> My goal is to give the table a drop shadow by assigning $scope.dndElemClass = 'on-drag-enter' on the element's ondragenter event listener: .on-drag-enter { -webkit-box-shadow: -3px 3px 5px 3px #ccc; ... } The onDragEnter directive is as follows: directive('dragAndDrop', function() { return { restrict: 'A', controller: function($scope) { $scope.dndElemClass = ''; }, link:

angularjs conditional directive only on desktop

萝らか妹 提交于 2019-12-08 07:04:41
问题 I want to put a directive on an element only if it's not viewed from mobile. As it's an externally maintained plugin I don't want to modify the directive itself. What's the easiest way of doing this? 回答1: Create a directive that performs the detection (or receives it), adds the directive if not viewed from mobile, removes itself from the element and then compiles the element. HTML: <div not-on-mobile="external-directive">Hello.</div> JS: app.directive('notOnMobile', function($compile) { //

angular input formatter/parser directive and interpolated attributes?

我与影子孤独终老i 提交于 2019-12-08 07:04:32
问题 I am attempting to write a configurable directive that is applied to an input element, which requires ngModel, and which adds a parser and a formatter function for ngModel. The problem I'm having is that I can't seem to pass interpolated values into the directive while simultaneously supporting ngModel binding. For instance, I want to be able to use my directive in one of two ways: passing literal arguments: <input ng-model="foo" my-directive="120" /> or passing interpolated arguments from

Passing ng-directive to Leaflet L.popup().setContent()

隐身守侯 提交于 2019-12-08 06:40:50
问题 Thank you for giving my question a look. Goal: Pass an Angular directive to the .setContent() method of L.popup() The Problem : I need to run $compile on the directive in order for it to enter ng. But something like .setContent($compile('<new_marker_form></new_marker_form')) yields a Failed to execute 'appendChild' on 'Node': The new child element is null. as I bet the ng is trying to compile before leaflet has actually appeneded any HTML. Not sure if this is better suited for Stack Overflow.

Calculate average from list of values in JSON

跟風遠走 提交于 2019-12-08 06:33:27
问题 I have a simple ng-repeat that displays a list of values (financial income). How can i calculate the average from this list? <div ng-repeat="data in MyData"> {{ data.income }} </div> <div> Average: </div> Which displays: 11 14 8 9 21 10 2 1 5 13 Thanks 回答1: In HTML Average: {{calculateAverage(MyData)}} Code $scope.calculateAverage = function(MyData){ var sum = 0; for(var i = 0; i < MyData.length; i++){ sum += parseInt(MyData[i], 10); //don't forget to add the base } var avg = sum/MyData

how to add a table row as a template using angular js

十年热恋 提交于 2019-12-08 05:57:54
问题 I would like to add a row dynamically to a table. I would like to reuse the row in a few tables. I tried doing this with a directive and by using ng-include but neither option worked as I expected. Basically, this is what I did: myapp.directive('myRow', function () { return { restrict : 'E', replace : true, scope : { mytitle : '@mytitle'}, template : '<tr><td class="mystyle">{{mytitle}}</td></tr>' } }); and in html: <table> <tbody> <tr><td>data</td></tr> <my-row></my-row> </tbody> </table>

Is it possible to have multiple directives on the same HTML element?

。_饼干妹妹 提交于 2019-12-08 05:48:09
问题 Is it possible to have two different directives on the same HTML element? <div directiveone directivetwo></div> or will that cause scope issues? 回答1: Yes you can and it's fairly common. The only potential issue with scope is you can't have multiple new scopes on the same element. Per the angular docs: "If multiple directives on the same element request a new scope, only one new scope is created." http://docs.angularjs.org/guide/directive 来源: https://stackoverflow.com/questions/19352649/is-it

Inner html add by ng-bind-html in angularjs

眉间皱痕 提交于 2019-12-08 05:47:29
问题 I am generating bootstrap navigation menu by using angular directive. All of the things were Ok but when I reached finally to generate dropdown menu then I need to generate HTML dynamically. To generate HTML I have used angular ng-bind-html. The angular ng-bind-html is creating HTML very well. The ng-bind-html generating HTML looks like this. <div ng-bind="getDropdownMenu(submenu)"> <ul class="dropdown-menu" role="menu"> <li><a href="#">Action</a></li> <li><a href="#">Another action</a></li>

How to get the rendered content from the `link` function of a directive?

限于喜欢 提交于 2019-12-08 05:42:09
问题 Html code: <div class="test">{{name}}</div> Angular code: var app = angular.module('angularjs-starter', []); app.controller('MainCtrl', function($scope) { $scope.name = 'World'; }); app.directive('test', function(){ return { restrict: 'C', link: function(scope, elm, attrs){ var content = elm.html(); alert(content); } } }); It will alert a string {{name}} . How to alert the rendered string World ? Live demo: http://plnkr.co/edit/Mov0AlkdE9B8yKiBjpnp?p=preview 回答1: You need to use $interpolate

autocompleted text in textbox does not add to table completely

ε祈祈猫儿з 提交于 2019-12-08 04:57:18
问题 I am new to angularjs, I have a textbox and I have a button and table: whenever user click on add button the data in the textbox would be added to the table: here is the link to my code: code everything works fine, but when it comes to autocomplete it starts acting funny, the autocomplete itselfe works fine but if for example add acti and the autocomplete suggests actionscript then if instead of writing the whole word you choose it from suggestins just he characters that you typed would be