angularjs-directive

Ng show if the variable is a number

余生颓废 提交于 2019-12-06 20:24:31
问题 I want to display an element only if a value is a number. How to do this? I tried : ng-show='angular.isNumber(10)' ng-show='isNumber(10)' 回答1: Add to your scope: $scope.isNumber = angular.isNumber; and then use: ng-show="isNumber(10)" http://jsfiddle.net/88wqe/ 回答2: <div ng-controller="Ctrl" ng-show="isNumber(num)"> AAA </div> function Ctrl($scope){ $scope.num = '10'; $scope.isNumber= function (n) { return !isNaN(parseFloat(n)) && isFinite(n); } } Here's a JS Fiddle http://jsfiddle.net/7RD47/

Angularjs currency format in input box with ng-model: how to get $formatters to fire on each input

痴心易碎 提交于 2019-12-06 20:12:13
问题 I have searched everywhere for this. Every stack overflow that has an answer, it does not actually work. Same with any examples or google group examples from for angular including the docs. Seems simple. I want a function to get called on an input for each key pressed by the user. simple input with a ng-model <input class="form-control" ng-model="model.thisisnotfun" formatter type="text" required> According to everything i read. $formatters should update the value from the model to the view

ng-change event only fires once for each radio button when created with ng-repeat

浪尽此生 提交于 2019-12-06 19:23:56
问题 I have created an AngularJS directive with radio buttons to control which environment my page will query against and added it to my page. I am using a two-way binding to map a local scope variable called environment to an app variable with the same name. It seems to work well when I create the radio buttons explicitly in the template (in my actual code I'm using templateUrl instead, but still have the same problem). <div> <label><input type="radio" name="env" ng-model="environment" ng-change=

AngularJS directive pass parameters through templateUrl function

自古美人都是妖i 提交于 2019-12-06 17:55:25
I'm trying to move my template from being in-line to it's own file. Everything was working before I changed from template to templateUrl Glenn.directive('test', function($compile) { return { restrict: 'A', priority: 1000, terminal: true, templateUrl: function(tElement, tAttrs) { return ('test.html'); }, link: function(scope, element, attrs) { attrs.$set('editable-text', 'content.' + attrs.edit + '.data'); attrs.$set('edit', null); $compile(element)(scope); } } }); test.html {{ 'content.' + tAttrs.edit + '.data' }} <button ng-click="' + tAttrs.edit + '_form'+ '.$show()" ng-hide="' + tAttrs.edit

Display AngularStrap Dropdown Manually - How?

我们两清 提交于 2019-12-06 17:53:55
问题 I am trying to display an AngularStrap dropdown manually, leveraging the trigger configuration on $dropdownProvider as such // how dropdown is triggered - click | hover | focus | manual app.config(function($dropdownProvider) { angular.extend($dropdownProvider.defaults, { trigger: 'manual' }); }); click hover focus all work fine, but why not manual ? I have yet to discover any proof that this offered api configuration option works. How can I do this? In fact, this issue seems to have been

unit test spy on $emit

我只是一个虾纸丫 提交于 2019-12-06 17:25:50
问题 I'm trying to spy on an $emit from a directive, but somehow I cannot get the spy to 'hear' the $emit. This is the code in my directives' controller: $scope.$on('send', function () { console.log('called'); $scope.$emit('resultSend', {'ok': true, 'data': ''}); }); This is my unit test: var $rootScope, $compile, elm, element; beforeEach(inject(function ($injector) { $rootScope = $injector.get('$rootScope'); $compile = $injector.get('$compile'); elm = angular.element('<test></test>'); element =

How to get ng-model value inside custom directive

旧时模样 提交于 2019-12-06 17:20:02
问题 I've searched here on SO and tried the answers I found, but I can't seem to get the model value out of the ngModel of my custom directive. Here's the directive /* *usage: <markdown ng:model="someModel.content"></markdown> */ breathingRoom.directive('markdown', function () { var nextId = 0; return { require: 'ngModel', replace: true, restrict: 'E', template: '<div class="pagedown-bootstrap-editor"></div>', link:function (scope, element, attrs, ngModel) { var editorUniqueId = nextId++; element

Problems getting Bootstrap DateRangePicker to work in filterHeaderTemplate with Modal popup in UI-Grid

浪尽此生 提交于 2019-12-06 17:02:53
问题 I'm trying to add a bootstrap DateRangePicker in the Filter Header Template for an Angular UI-Grid. I can see that the template is working properly because it shows the Bootstrap Icon. I do not want to use the native angular Type:'date'. I want to use a bootstrap date picker. I have a Plunker as an example further down, that shows the native datepicker working and the Bootstrap Datepicker button clickable but not displaying anyting. I have all the includes needed for this to show up. <!--

AngularJS - Pass dynamic object value and call function from Directive

空扰寡人 提交于 2019-12-06 16:44:37
Ctlr.js app.controller('myCtrl', function($scope) { $scope.data = { waterMarkImgPosition: [ {id: 'lowerRight', name: 'Lower Right'}, {id: 'lowerLeft', name: 'Lower Left'}, {id: 'upperRight', name: 'Upper Right'}, {id: 'upperLeft', name: 'Upper left'}, {id: 'center', name: 'Center'} ], selectedPosition: {id: 'upperRight', name: 'UpperRight'} //This sets the default value of the select in the ui }; $scope.watermarkPosition = $scope.data.selectedPosition.id; //pass default position for watermark }); Directive.js app.directive('waterMark', function($timeout) { return { restrict: 'EA', link:

Angularjs - hide div with “if” and “else”

喜欢而已 提交于 2019-12-06 16:35:26
问题 I would only like to show a div when user is logged in and on their profile but disabled when logged off and on another users profile. I attempted to do this below but was unsuccessful. I would like to know what is the best possible way of going about this? Service.js (function () { 'use strict'; angular .module('app.authentication.services') .factory('Authentication', Authentication); Authentication.$inject = ['$cookies', '$http']; function Authentication($cookies, $http) { var