angularjs-directive

Angularjs: Compile ng-repeat dynamically

独自空忆成欢 提交于 2021-02-19 05:33:36
问题 I have found some strange behavior with Angularjs. My directive simply adds and compiles ng-repeat to my dom element. However the scope variable item is not accessible. Look at the code below for explanation. var demo = angular.module('demo', []); demo.directive('customRepeat', function($compile) { return { priority: 2000, restrict: 'A', compile: function(element){ element.attr('ng-repeat', 'item in [1,2,3,4,5,6]') return function(scope, element) { $compile(element)(scope) } } } }); <script

Limit rows in HTML5 textarea

匆匆过客 提交于 2021-02-10 15:41:21
问题 I'm looking for a solution to a problem, but I'm not able to find it. It could be in AngularJS or in Javascript (then I'll translate it in AngularJS). The problem is that I have to limit the rows of a simple textarea. The attribute 'rows=x' of HTML5 limit just the view. I have to limit the lines. The problem is that even if graphycally the lines go down, the components looks at it as a unique line. The user has to press ENTER to create a new line. But, I have to limit the lines. I did this

AngularJS <input> with type set to 'number', how to force a initial display of value to a non-number string

落爺英雄遲暮 提交于 2021-02-10 14:51:39
问题 I am wondering using Angular, if the <input> has 'type' set to 'number', can you force a initial display of a non-number string if ng-model is initialized to certain number (0 in my example)? My example code is here: http://plnkr.co/edit/TwraJlxZSd3TeSYscExq?p=info This topic is related to: [1]: 'AngularJS directives to hide zero when <input> is initially loaded to the DOM' and: [2]: 'Hide Value in input when it's zero in angular Js' 回答1: The following directive will solve your problem, app

Dynamically generating validation attribute on input using interpolation

天大地大妈咪最大 提交于 2021-02-10 05:24:45
问题 Edit: This question is no longer relevant as of Angular version: 1.3.0-beta.12 you can now parse ng-minlength and ng-maxlength dynamic values. See: https://github.com/angular/angular.js/issues/5319 My problem is quite simple: I need to dynamically create input validation (ex. ng-minlength ) using interpolation. And doing that I am running into some issues specifically generating the validation attributes for ng-minlength and ng-maxlength . I assume this is due to them only taking constants?

Angularjs Custom select2 directive

穿精又带淫゛_ 提交于 2021-02-05 22:43:38
问题 I have created simple custom AngularJs directive for this awesome jquery plugin jQuery-Select2 as follows: Directive app.directive("select2",function($timeout,$parse){ return { restrict: 'AC', link: function(scope, element, attrs) { $timeout(function() { $(element).select2(); },200); } }; }); Usage in HTML templates: <select class="form-control" select2 name="country" data-ng-model="client.primary_address.country" ng-options="c.name as c.name for c in client.countries"> <option value=""

Angular Bootstrap UI Datepicker with custom directive $parser causes error: Not a valid date ng model

跟風遠走 提交于 2021-01-29 07:45:57
问题 I am trying to use the angularjs bootstrap ui datepicker directive on an input element that also has another directive that adds a $parser to the model. I get an error because the model object is not a Date object (because the parser causes the mdoel object to be an object with property named, "customValue". The actual error when I select a date is, "Datepicker directive: "ng-model" value must be a Date object, a number of milliseconds since 01.01.1970 or a string representing an RFC2822 or

Angularjs ui typeahead to focus after select

拜拜、爱过 提交于 2021-01-29 03:09:44
问题 You can even see the problem in the angular ui's demo. http://angular-ui.github.io/bootstrap/ Typeahead once you select a suggested value loses focus on the input prevent you from submitting it. How do I get it to focus on the input after a suggested value is clicked upon. 回答1: Put this line into typeahead.js:148 select function. element[0].focus(); See here: http://plnkr.co/edit/XB5ybI?p=preview 来源: https://stackoverflow.com/questions/16955353/angularjs-ui-typeahead-to-focus-after-select

Angular - splice function always removes last element

跟風遠走 提交于 2021-01-27 12:11:58
问题 I have an array of objects that I want to remove certain objects when a Delete key is clicked. However, it always removes the last item from the rows array, no matter how many rows I have created. Even if I explicitly put in a line like so, $scope.rows.splice(1,1) - it will still remove the last element, not the second. JS angular.module('app', ['ngAnimate', 'ui.bootstrap']) .directive('queryBuilder', function() { return { restrict: 'E', scope: {}, controller: function($scope) { $scope.rows =

Angular - splice function always removes last element

让人想犯罪 __ 提交于 2021-01-27 12:07:08
问题 I have an array of objects that I want to remove certain objects when a Delete key is clicked. However, it always removes the last item from the rows array, no matter how many rows I have created. Even if I explicitly put in a line like so, $scope.rows.splice(1,1) - it will still remove the last element, not the second. JS angular.module('app', ['ngAnimate', 'ui.bootstrap']) .directive('queryBuilder', function() { return { restrict: 'E', scope: {}, controller: function($scope) { $scope.rows =

Pass object to component

删除回忆录丶 提交于 2021-01-26 19:49:48
问题 I have created a component that needs to have a reference to the object for which the component was created. I didn't make to work and all my trials have failed. Below, I try to describe the intention. The component definition would maybe look like this: angular .module('myModule') .component('myComponent', { templateUrl: "template.html", controller: [ MyController ], bindings: { myObject: '=' } }); function MyController(myObject) { var vm = this; vm.myObject = myObject; } In a service I