angularjs-directive

ng-repeat inserting empty anchor tags

梦想的初衷 提交于 2019-12-22 10:15:10
问题 I'm trying to create a menu using angular. A menu item can have children requiring another ng-repeat to print the sub nav items. I'm noticing some strange behavior when attempting to insert an anchor tag within the 2nd ng-repeat. Link to fiddle: http://jsfiddle.net/npU7t/ <li ng-repeat="sub_menu_item in menu_item.sub_menu"> <a href=""> {{ sub_menu_item.title }} </a> </li> With { title: 'menu item with children', sub_menu: [ { title: '<-- empty anchor tag???' } ] } Results in <li ng-repeat=

Submitting a form within Karma process => Some of your tests did a full page reload

会有一股神秘感。 提交于 2019-12-22 10:13:24
问题 In one angular directive, I have this code: $('[name=' + formName + ']').bind('submit', function () { validate(); }); In the beforeEach clause of a Karma test, I have this code: bootstrapInput = $compile('<form novalidate name="aForm">' + '<input-field icon="true" for="email">' + '<div>' + '<input class="form-control" class="email" name="email" id="email" type="email" ng-model="user.email" required />' + '</div>' + '<input-validation for="email" custom-error="custom error" required="Email is

Need help in creating network graph using visjs in angularjs

旧巷老猫 提交于 2019-12-22 10:06:34
问题 I need help in making this plunker work something similar to this vis example in angularjs. I am using <vis-network data="data" options="options"></vis-network> tag and below data and options data var nodes = [ {id: 1, label: 'Node 1'}, {id: 2, label: 'Node 2'}, {id: 3, label: 'Node 3'}, {id: 4, label: 'Node 4'}, {id: 5, label: 'Node 5'} ]; var edges = [ {from: 1, to: 3}, {from: 1, to: 2}, {from: 2, to: 4}, {from: 2, to: 5} ]; $scope.data = VisDataSet({ nodes: nodes, edges: edges }); options

AngularJS: Dropdown directive with custom ng-options

六月ゝ 毕业季﹏ 提交于 2019-12-22 09:14:20
问题 I'm trying to create a dropdown directive where i want to specify the selects ng-options "option value" and "option description" attributes by specifying them with the directives attributes. See code for a better understanding... Here is my directive. This will obviously not work, but i think it will describe what i'm trying to do... app.directive('dropdown', function(){ return { restrict: 'E', scope: { array: '=' }, template: '<label>{{label}}</label>' + '<select ng-model="ngModel" ng

Bind event to child element of directive in link function

南笙酒味 提交于 2019-12-22 08:59:30
问题 Need to bind an event to directive's children which is prepared with ng-repeat in templateUrl. I am trying to bind the event in link function but the children are not yet prepared. Here is the plunker. Here I want to bind click event on li tag which are prepared with ng-repeat.But by the time, the link is executed, the li elements are not yet prepared. Can somebody please help. 回答1: I've resolved the same problem with the angular $timeout link: function (scope, element) { $timeout(function ()

How to dynamically add a custom directive to a div element?

假装没事ソ 提交于 2019-12-22 08:31:16
问题 I'm a beginner at angularjs, please take it easy on me. So I have this directive and would like to dynamically append it to a div element. How should I do it? appDirectives.directive('test', function () { return { restrict: 'E', templateUrl: 'templates/test.html' } }); I tried this but it didn't work. I'm assuming the template didn't get compiled before I appended to the div element. Is there an angular way to do this? <div id="element"></div> $('#element').append(<test></test>); Update: Here

Applying angular2 form directives to custom input form elements

寵の児 提交于 2019-12-22 08:16:56
问题 I want to create a custom InputCustom component and use it to create model-driven forms. My custom component just wraps an input field and uses Bootstrap material design for look'n'feel. @Component({ selector:'inputCustom', template:` <div class="form-group label-floating is-empty"> <label class="control-label" for="input">Type here</label> <input class="form-control" id="input" type="text"> <p class="help-block">Some help text</p> <span class="material-input"></span> </div> `}) class

angular + jasmine + mock $stateParams in a directive

南笙酒味 提交于 2019-12-22 08:08:34
问题 What is the best approach to mock $stateParams in a directive? $stateParam members will be changed according to the test. I can easily mock $stateParams in a controller using $controller('ctrl', $stateParams) but dont know how to modify $stateParams that gets injected into the directive. I've gone the route of decorating $stateParams with the below but can only declare that when i create the module. as i mentioned, $stateParam members will change many times through the different tests.

AngularJS : Initializing isolated scope inside a directive

眉间皱痕 提交于 2019-12-22 07:18:12
问题 I have created a directive that accepts some attributes and initializes the isolated scope with these attributes. If an attribute isn't specified, then the isolated scope should be initialized with a calculated value. I added a link function that inspects the scope and initializes the default values (if no value has been set using the attributes). The scope has been initialized, but if I set a default value then it will be overwritten later by the framework. A workaround is to use $timeout(..

How does the createSpy work in Angular + Jasmine?

自作多情 提交于 2019-12-22 07:08:17
问题 I made a simple demo of a factory and I am trying to test this using jasmine . I am able to run the test but I am using the spyOn method. I would rather use jasmine.createSpy or jasmine.createSpyObj to do the same test. Could someone help me to refactor my code so that uses these methods instead in my example? http://plnkr.co/edit/zdfYdtWbnQz22nEbl6V8?p=preview describe('value check',function(){ var $scope, ctrl, fac; beforeEach(function(){ module('app'); }); beforeEach(inject(function(