angularjs-directive

AngularJS : how to create DOM and bind to a model based on arbitrary hierarchical data

风流意气都作罢 提交于 2020-01-17 11:34:50
问题 Angularjs: complex directive in ng-repeat, how to bind the ngModel or ngChecked in directive and make it work? given the array: +----+-----------+----------+----------+-------+ | id | name | parentid | haschild | value | +----+-----------+----------+----------+-------+ | 1 | parent | null | false | true | | 2 | id1 child | 1 | true | true | | 3 | id2 child | 2 | true | true | | 4 | id3 child | 3 | false | true | | 5 | id1 child | 1 | true | true | | 6 | id5 child | 5 | false | true | +----+--

AngularJS : how to create DOM and bind to a model based on arbitrary hierarchical data

人盡茶涼 提交于 2020-01-17 11:34:13
问题 Angularjs: complex directive in ng-repeat, how to bind the ngModel or ngChecked in directive and make it work? given the array: +----+-----------+----------+----------+-------+ | id | name | parentid | haschild | value | +----+-----------+----------+----------+-------+ | 1 | parent | null | false | true | | 2 | id1 child | 1 | true | true | | 3 | id2 child | 2 | true | true | | 4 | id3 child | 3 | false | true | | 5 | id1 child | 1 | true | true | | 6 | id5 child | 5 | false | true | +----+--

Angular issue with asynchronous call to function

混江龙づ霸主 提交于 2020-01-17 05:38:18
问题 I'm working with an Angular directive which loads JSON data from localStorage . This was easily done with localStorage.getItem(id) , but now I am trying to make it work via an API call (which in turn pulls from a database). I have the Angular factory code working, and the http requests working, but in the directive code there's a _handleAsyncLoad() function which is throwing me. In other words, I'm trying to use the built-in promise for the serialized object coming back from the API layer. ex

AngularJS : Replicate div on click of button

百般思念 提交于 2020-01-17 05:37:10
问题 I want to replicate the text fields(div) present in image every time the user click on '+' button. 回答1: If I understood your question properly , pls refer the below code . Template <div ng-app="myapp" ng-controller="myCtrl"> <div ng-repeat="item in items"> <input type="text" placeholder="name"> <input type="text" placeholder="email"> <button ng-click="add()">+</button> <p>Some text some text some text</p> </div> </div> controller var app = angular.module('myapp',[]); app.controller('myCtrl',[

Removing directive attribute does not remove listener

一世执手 提交于 2020-01-17 05:00:25
问题 I have a button with a ng-click attribute. If I remove the ng-click attribute, the listener persists. How can I remove the event listener when I remove the ng-click attribute? angular.module('testApp', ['ng']) .directive('testDir', testDir) .controller('testCtrl', testCtrl); function testDir() { return { compile: (elem, attrs) => { // Remove ng-click attribute elem.removeAttr('ng-click'); } }; } function testCtrl($scope) { $scope.count = 0; $scope.handleClick = function() { $scope.count++; }

On click How can I cycle through JSON one by one in AngularJS

北战南征 提交于 2020-01-17 04:52:08
问题 Creating my first directive as an exercise in angular —making more or less a custom carousel to learn how directives work. I've set up a Factory with some JSON data: directiveApp.factory("Actors", function(){ var Actors = {}; Actors.detail = { "1": { "name": "Russel Brand", "profession": "Actor", "yoga": [ "Bikram", "Hatha", "Vinyasa" ] }, "2": { "name": "Aaron Bielefeldt", "profession": "Ambassador", "yoga": [ "Bikram", "Hatha", "Vinyasa" ] }, "3": { "name": "Adrienne Hengels", "profession":

AngularJS DOM Manipulation through Directives

此生再无相见时 提交于 2020-01-17 01:47:08
问题 Currently I have a working angular app .... It works but im doing some DOM manipulation stuff in my controller rather than in a directive like i should. The problem is and my question becomes, HOW do i implement this type of functionality properly using directives?? A simple example is: <div id="container1"></div> <button type="button" ng-click="changeSize(1)">Small</button> <button type="button" ng-click="changeSize(2)">Medium</button> <button type="button" ng-click="changeSize(3)">Large<

Jasmine - How to test a stylesheet directive

岁酱吖の 提交于 2020-01-16 20:36:16
问题 I have written a directive that interrogates the current URL, and loads the corresponding freestyle. The problem i am facing is how can i test the link function: HTML: <html lang="en" ng-app="myApp"> <head> <meta charset="UTF-8"> <title>CSS Test</title> <link get-style-directive /> </head> Directive: app.directive('getStyleDirective', ["$compile", "$location", function($compile, $location) { return { replace: true, scope: true, link: function(scope, element, attrs) { var urlValue = $location

How to use a directive to dynamically change a template?

蹲街弑〆低调 提交于 2020-01-16 18:47:13
问题 I have this directive angular.module('starter.directive', []) .directive('answer', ['Helper', function (Helper) { return { require: "logic", link: function (scope, element, attrs, logicCtrl) { var htm = ''; if(logicCtrl.test == 'a') { htm = '<p>a</p>' } if(logicCtrl.test == 'b') { htm = '<p>b</p>' } }, template: '' // somehow use htm here } }]); I'm trying to use the htm for the template , Any ideas? 回答1: You can just put htm into scope of directive and use it inside template. angular.module(

How to use a directive to dynamically change a template?

白昼怎懂夜的黑 提交于 2020-01-16 18:44:09
问题 I have this directive angular.module('starter.directive', []) .directive('answer', ['Helper', function (Helper) { return { require: "logic", link: function (scope, element, attrs, logicCtrl) { var htm = ''; if(logicCtrl.test == 'a') { htm = '<p>a</p>' } if(logicCtrl.test == 'b') { htm = '<p>b</p>' } }, template: '' // somehow use htm here } }]); I'm trying to use the htm for the template , Any ideas? 回答1: You can just put htm into scope of directive and use it inside template. angular.module(