angularjs-directive

AngularJS – append row after element in directive

跟風遠走 提交于 2019-12-30 08:17:12
问题 My question is similar as this one, but instead of prepending row, I want it to append. This doesn’t work: app.directive('createTable', function ($compile) { return { link: function (scope, element, attrs) { var contentTr = angular.element('<tr><td>test</td></tr>'); contentTr.parentNode.insertBefore(element, contentTr.nextSibling); $compile(contentTr)(scope); } } }); 回答1: This does the job: app.directive('createTable', function ($compile) { return { link: function(scope, element, attrs) { if

How can I use a registered controller in my angular directive?

人走茶凉 提交于 2019-12-30 08:04:35
问题 I have a controller registered like this: myModule.controller('MyController', function ($scope, ...some dependencies...) { .... Using ng-controller="MyController" in the HTML it all works fine, but now I want to use this controller as my directive's controller. Some thing like this: otherModule.directive('myDirective', function() { return { restrict: 'A', replace: true, controller: ??????????, scope: { foo: '=', blah: '=', }, template: '....' } }); I tired just putting MyController but it

How can I use a registered controller in my angular directive?

天涯浪子 提交于 2019-12-30 08:04:24
问题 I have a controller registered like this: myModule.controller('MyController', function ($scope, ...some dependencies...) { .... Using ng-controller="MyController" in the HTML it all works fine, but now I want to use this controller as my directive's controller. Some thing like this: otherModule.directive('myDirective', function() { return { restrict: 'A', replace: true, controller: ??????????, scope: { foo: '=', blah: '=', }, template: '....' } }); I tired just putting MyController but it

Angular on video load event

情到浓时终转凉″ 提交于 2019-12-30 06:53:59
问题 I'm still trying to understand angular... Basically, I have an html5 video and I want to listen to the onloadeddata event (http://www.w3schools.com/jsref/event_onloadeddata.asp). This is what I have: html: <video autoplay="autoplay" loaded-data loop style="display: none;"> <source src="videos/example.mp4" type="video/mp4"> <source src="videos/example.ogg" type="video/ogg"> </video> directive: angular.module('myApp') .directive('loadedData', function () { return function ($scope, $element) {

how to show html on pop over using angular ui bootstrap?

强颜欢笑 提交于 2019-12-30 05:48:06
问题 I make demo of pop over like this .It show a pop over on right side when I click the button .But now problem is that how I will show some html on pop over . <html ng-app="plunker"> <head> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.js"></script> <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.11.0.js"></script> <script src="example.js"></script> <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"> </head>

AngularJS: “Error: Unexpected call to method or property access.undefined” only in IE 8

你说的曾经没有我的故事 提交于 2019-12-30 03:48:08
问题 Have you ever had the error "Error: Unexpected call to method or property access.undefined" only IE8? What was causing it? How did you solve it? -- Note: It assumes the same code works fine in Chrome, Firefox, Safari Edit: Context I'm building a facebook page tab plugin with AngularJS + Google App Engine Python. I use a dozen custom directives either written by me or by the angular-ui team and 4-5 controllers. Everything works fine in Chrome, Safari and Firefox, but not in IE8. 回答1: The

Angular Directive Does Not Evaluate Inside ng-repeat

巧了我就是萌 提交于 2019-12-30 02:12:08
问题 I have the following setup: App/Directive var app = angular.module("MyApp", []); app.directive("adminRosterItem", function () { return { restrict: "E", scope: { displayText: "@" }, template: "<td>{{ displayText }}</td>", // should I have this? link: function(scope, element, attrs){ // What do I put here? I don't seem to have any // element to initialize (set up event handlers, for example) }, compile: function(?,?,?){} // should I have this? If so, what goes inside? } }); Controller function

AngularJS animate image on src change

无人久伴 提交于 2019-12-30 02:11:08
问题 I have an AnuglarJS app, where I load/change some images from a webservice... Controller .controller('PlayerCtrl', function($scope, programService) { .... programService.refresh(function(data) { $scope.program = data; }); .... Template <img src="{{program.image}}" /> When my app updates from the webservice the images changes as expected, I just want to make an fadeout / fadein when this happens, how can that be done? Is it possible to always make a fadeout/in when a image src changes? 回答1:

Angular.js caching $compiled templates / rendering performance of directives inside ng-repeat

♀尐吖头ヾ 提交于 2019-12-30 01:38:33
问题 I have a a directive which renders table cell(see how the way I'm compiling it here, basically using $compile inside link fn Angular.js directive template using variable from parent/inherited scope), now this is used inside two ng-repeat s, one for rows, one for columns, so it's basically <ng-repeat row in rows> <ng-repeat column in columns> <my-cell-directive /> </ng-repeat> </ng-repeat> with 50 rows and 8 columns its got a pretty big(well pretty noticeable anyway) impact on (rendering)

angularjs directive call function specified in attribute and pass an argument to it

孤街浪徒 提交于 2019-12-29 10:09:32
问题 I want to create a directive that links to an attribute. The attribute specifies the function that should be called on the scope. But I also want to pass an argument to the function that is determined inside the link function. <div my-method='theMethodToBeCalled'></div> In the link function I bind to a jQuery event, which passes an argument I need to pass to the function: app.directive("myMethod",function($parse) { restrict:'A', link:function(scope,element,attrs) { var expressionHandler =