angularjs-directive

creating a new directive with angularjs

人盡茶涼 提交于 2019-12-17 13:09:06
问题 so i'm making a simple directive called "hover", it's a basic nav menu that when you pass a mouse over a specific aba, this aba changes the color. See my script code: var app = angular.module('myModule', []); app.directive('hover', function(){ return{ restrict: 'E', controller: function($scope) { $scope.hover = null; $scope.selected = null; $scope.onHover = function (index){ $scope.hover = index; } $scope.mouseLeave = function(){ if($scope.selected) $scope.hover = $scope.selected; else $scope

AngularJS filter based on array of strings?

让人想犯罪 __ 提交于 2019-12-17 10:42:51
问题 I'm having a hard time wrapping my head around how to go about doing an Angular filter to solve a problem that I'm running into. Here's a basic example of my data structure, an array of tasks: var tasks = [ { Title: "This is a task title", Tags: ["Test","Tag","One","Two","Three"] }, { Title: "Another test tag title", Tags: ["Some", "More", "Tags"] }, { Title: "One more, why not", Tags: ["I","Like","Dirt"] }, { Title: "Last one!", Tags: ["You","Like","Dirt"] } ]; So each object has an array of

How to create a directive with a dynamic template in AngularJS?

感情迁移 提交于 2019-12-17 10:26:36
问题 How can I create a directive with a dynamic template? 'use strict'; app.directive('ngFormField', function($compile) { return { transclude: true, scope: { label: '@' }, template: '<label for="user_email">{{label}}</label>', // append replace: true, // attribute restriction restrict: 'E', // linking method link: function($scope, element, attrs) { switch (attrs['type']) { case "text": // append input field to "template" case "select": // append select dropdown to "template" } } } }); <ng-form

AngularJS Manually Render Controller and Template

放肆的年华 提交于 2019-12-17 10:18:59
问题 I'm trying to implement a plugin system in angularjs that would allow users to configure which "widgets" they will see on a certain page. Each widget is defined by a controller and a template(url). Is it possible to create a directive that instantiates a controller, invokes it with a template and transcludes the resulting content? The goal is something like this: <div class="widget" ng-repeat="widget in widgets"> <widget controller="widget.controller" templateUrl="widget.templateUrl"></widget

When to use the AngularJS `$onInit` Life-Cycle Hook

六月ゝ 毕业季﹏ 提交于 2019-12-17 09:54:43
问题 With the release of AngularJS V1.7, the option to pre-assign bindings to has deprecated and removed: Due to 38f8c9, directive bindings are no longer available in the constructor . To migrate your code: If you specified $compileProvider.preAssignBindingsEnabled(true) you need to first migrate your code so that the flag can be flipped to false . The instructions on how to do that are available in the "Migrating from 1.5 to 1.6" guide. Afterwards, remove the $compileProvider

Illegal use of ngTransclude directive in the template

我怕爱的太早我们不能终老 提交于 2019-12-17 09:33:32
问题 I have two directive app.directive('panel1', function ($compile) { return { restrict: "E", transclude: 'element', compile: function (element, attr, linker) { return function (scope, element, attr) { var parent = element.parent(); linker(scope, function (clone) { parent.prepend($compile( clone.children()[0])(scope));//cause error. // parent.prepend(clone);// This line remove the error but i want to access the children in my real app. }); }; } } }); app.directive('panel', function ($compile) {

ng-click doesn't work within the template of a directive

懵懂的女人 提交于 2019-12-17 09:19:46
问题 Angular noob here. I am creating a directive to recursively display a tree of questions and sub questions. I am using a link in the template which calls a function within the scope. For some reason, it does't call the editQuestion() method. Here's the code and the fiddle http://jsfiddle.net/madhums/n9KNv/ HTML: <div ng-controller="FormCtrl"> <questions value="survey.questions"></questions> </div> Javascript: var app = angular.module('myApp', []); function FormCtrl ($scope) { $scope

Directive is being rendered before promise is resolved

六月ゝ 毕业季﹏ 提交于 2019-12-17 08:30:13
问题 I am having issues getting my directive to render its content only after my promise has been resolved. I thought then() was supposed to do this but it doesn't seem to be working.. Here is my controller: // Generated by CoffeeScript 1.6.3 (function() { var sprangularControllers; sprangularControllers = angular.module('sprangularControllers', ['sprangularServices', 'ngRoute']); sprangularControllers.controller('productsController', [ '$scope', '$route', '$routeParams', 'Product', 'Taxonomy',

AngularJS leaves comments in HTML: is it possible to remove them?

僤鯓⒐⒋嵵緔 提交于 2019-12-17 07:25:07
问题 Does anyone knows if you can remove the angular comments that are left in html code? For example: If I use ngRepeat and there are no items to repeat over, AngularJS leaves this : <!-- ngRepeat: post in posts --> 回答1: This comment is a result of the element transclusion performed by ngRepeat . Looks like it's been happening nearly since the dawn of time (in angular terms) and will be created whenever a directive asks for element transclusion. While you certainly could wipe it out with direct

Call a method of a controller from another controller using 'scope' in AngularJS

这一生的挚爱 提交于 2019-12-17 07:13:01
问题 I am trying to call a method of second controller in first controller by using scope variable. This is a method in my first controller: $scope.initRestId = function(){ var catapp = document.getElementById('SecondApp'); var catscope = angular.element(catapp).scope(); catscope.rest_id = $scope.user.username; catscope.getMainCategories(); }; I am able to set the value of rest_id but I cannot call getMainCategories for some reason. The console shows this error: TypeError: Object # has no method