angularjs-directive

Different transitions with AngularJS

断了今生、忘了曾经 提交于 2020-01-11 10:46:09
问题 How can I enable different transitions with AngularJS. Lets Say, I have a sidebar in my web application. I the user clicks a button X, the sidebar should disappear very fast, if the user clicks another button, the sidebar should disappear slow. I think, this would work by setting a transition option value after one of that clicks and then changing the visibility state of the sidebar (watched by the transition directive). But that seems a bit like bad style for me. Is there a common way to do

AngularJs get Timestamp from a human readable date

情到浓时终转凉″ 提交于 2020-01-11 06:01:34
问题 Is there a way in angular JS to get Timestamp from a date obtained by a form? <label for="start">From:</label> <input type="date" ng-model="startDate" /> What will I have to write in the directive to transform this data? I didn't find anything about this particular issue, Regards 回答1: Use a directive to change the value from view to model. http://jsfiddle.net/bateast/Q6py9/1/ angular.module('app', []) .directive('stringToTimestamp', function() { return { require: 'ngModel', link: function

Angular directive to display Flash via <object> tag causes Flash to attempt to load {{expression}}

半腔热情 提交于 2020-01-10 15:43:08
问题 I have an AngularJS directive: myApp.directive('movie', function(){ return { restrict: 'E', replace: true, scope: { product:'=', codebase: '@' }, template: '<object style="width:550px;height:320px;" name="movie" id="movie" codebase="{{codebase}}"' + ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" tabindex="-1">' + '<param value="{{product.flashURL}}" name="movie">' + '<param value="true" name="play">' + '<param value="true" name="menu">' + '<param value="transparent" name="wmode">' + '

What's the difference between the 2 “postLink” functions in directive?

时间秒杀一切 提交于 2020-01-10 10:35:10
问题 From the doc of angularjs, when defining a directive, there's a postLink in compile , and a postLink in link myModule.directive('directiveName', function factory(injectables) { var directiveDefinitionObject = { priority: 0, template: '<div></div>', templateUrl: 'directive.html', replace: false, transclude: false, restrict: 'A', scope: false, compile: function compile(tElement, tAttrs, transclude) { return { pre: function preLink(scope, iElement, iAttrs, controller) { ... }, post: function

Create read more link in AngularJS

倾然丶 夕夏残阳落幕 提交于 2020-01-10 08:27:23
问题 I want to create a link with read more text. if there are more than 3 lines in a paragraph this link should be visible and clicking on this it show display all the lines. 回答1: I wanted to do the same thing, so I created a directive. Have a look here: https://gist.github.com/doukasd/0744566c5494ebc8643f Usage is pretty simple: <p data-dd-collapse-text="100">{{veryLongText}}</p> Where 100 is the character limit you want to specify. UPDATE: dd-text-collapse 回答2: For read more , you can use

Getting $parent.$index inside a custom directive

。_饼干妹妹 提交于 2020-01-10 06:14:26
问题 <li ng-repeat="value in array1 track by $index"> <div ng-repeat="j in array2"> <div example-directive > <p> {{$index}} ,{{$parent.$index}}</p> </div> </div> </li> In the above code I couldnt access parent ng-repeat index inside my custom directive.how can I get the index of parent ng-repeat 回答1: This sample can helps you to figure out how can get index or etc ... in directives. var app = angular.module("app", []); app.controller("controller", function ($scope) { $scope.array1 = [ {id: "1-1"},

AngularJS - Run custom directive after ng-bind-html

廉价感情. 提交于 2020-01-10 04:16:05
问题 I've a scenario which I want to run a custom directive on the DOM that ng-bind-html create. Basicly I've to customize the behavior of the html tag <a> because the html that is loading is unsafe and when the user click the link I've to execute some functions before anything happens, aka, the click event of jqLite. So my original ideia was create a directive that modifies the behavior of any <a> inside the container that I put the attribute of my directive. This works fine, until I combine with

AngularJS - accessing ng-click in custom directive

邮差的信 提交于 2020-01-10 02:30:07
问题 I'm trying to get my head around directives, i can easily use the template function to throw out my HTML, however, if i have an ng-click within my template, how can i access it within the link function? My directive: app.directive('directiveScroll', function () { return { restrict: 'AE', replace: 'true', template: '<div class="scroll-btns">' + '<div class="arrow-left" ng-click="scrollLeft(sectionID)"></div>' + '<div class="arrow-right" ng-click="scrollRight(sectionID)"></div>' + '</div>',

Getting select rows from ng-grid?

旧城冷巷雨未停 提交于 2020-01-09 19:52:47
问题 How do I create (or access) an array of selected rows in my ng-grid? Documentation (scroll to "Grid options") id | default value | definition ----------------------------------------------- selectedItems | [] | all of the items selected in the grid. In single select mode there will only be one item in the array. index.html <body ng-controller="MyCtrl"> <div class="gridStyle" ng-grid="gridOptions"></div> <h3>Rows selected</h3> <pre>{{selectedItems}}</pre> </body> main.js var app = angular

angular ng-repeat with condition

走远了吗. 提交于 2020-01-09 09:52:51
问题 How do you do something like this in angular with ng-repeat? I'll be using the example from the documentation which inits an array with 2 friends, what if I wanted to only do a repeat for all friends that are 26 and older? <!doctype html> <html ng-app> <head> <script src="http://code.angularjs.org/1.0.6/angular.min.js"></script> </head> <body> <div ng-init="friends = [{name:'John', age:25}, {name:'Mary', age:28}]"> I have {{friends.length}} friends. They are: <ul> <li ng-repeat="friend in