Am I misusing directives with too much logic?

Am I misusing directives with too much logic?

By : user2955180
Date : November 22 2020, 10:38 AM
it helps some times Probably your question might be answered more like expressing opinions than offer "right solutions".
I personally wouldn't introduce a controller to a directive if the directive doesn't expose logic which can be used by other directives (require: "^myDirective"). So most of my directives have the code you put into the controller in their link: function (scope, element, attrs) {}.
code :

Share : facebook icon twitter icon
Conditional logic in ng-class in directives template

Conditional logic in ng-class in directives template

By : Chea
Date : March 29 2020, 07:55 AM
may help you . I'm using AngularJS and i'm writing my own directive. I want to use conditional logic in my custom directive. The problem is caused in the template part. Here's a piece of my code: , You have to escape the apostrophes
code :
'<i class="fa" ng-class=" { \'fa-angle-up\': !isCollapsed, \'fa-angle-down\': isCollapsed } "></i>'
How to further abstract directives that have too much duplicated logic

How to further abstract directives that have too much duplicated logic

By : user3354116
Date : March 29 2020, 07:55 AM
should help you out This looks like a perfect use case for use of a 'required' directive. Take a look at the docs for 'require' attribute of the directive definition object.
For instance, you can define a directive called someObject and require it in your custom directive.
code :
<my-directive some-object="somethingOnParentScope"></my-directive>
return {
    restrict: 'A',
    require: 'someObject',

link: function( scope, element, attrs, someObjectCtrl ) {
  // if you need to make someObjectCtrl functionality available through templates, 
  // you will still need to add it to the scope
  scope.someFunction = someObjectCtrl.someFunction;
Combine 2 Knockout directives with similar logic

Combine 2 Knockout directives with similar logic

By : R. Ferland
Date : March 29 2020, 07:55 AM
To fix the issue you can do You can simply have a single function on click event and then inside the function compare if there is a change that needs to be asked.
Here is a simple example : https://jsfiddle.net/kyr6w2x3/110/
code :
<form data-bind="visible:ShowForm">
  <input type="text" data-bind="textInput:Input">
  <input type="button" value="Cancel" data-bind="click:CancelForm">

<div data-bind="text:Status">

 var MainViewModel = function() {
     var self = this;
     self.Input = ko.observable();
     self.Status = ko.observable();
     self.ShowForm  = ko.observable(true);
     self.canSave  = ko.observable(false);
    self.CancelForm = function(){
          self.Status("there is a change that needs to be asked the user");
            self.Status("there is no change so the form got hidden")
 ko.applyBindings(new MainViewModel ()); 
AngularJS: directives vs. controllers - What logic to put where?

AngularJS: directives vs. controllers - What logic to put where?

By : Tundra Fizz
Date : March 29 2020, 07:55 AM
I hope this helps . First of all, great question. I think every new-with-angular developer struggles with the differences with all the given components (controller, directive, service, filter etc.).
Let's start with the basic formal definition:
Is it good practice to use directives for splitting controller logic in angular?

Is it good practice to use directives for splitting controller logic in angular?

By : Max
Date : March 29 2020, 07:55 AM
will be helpful for those in need You are aiming at the right direction. Breaking a large controller into more smaller components in the form of directives is the way to go but I would suggest you to introduce few changes.
Related Posts Related Posts :
  • jQuery Sparkline in a cell in ng-grid using CellTemplate and Directive
  • AngularJS determine filter in controller
  • How to deploy an app using ionic framework to Amazon? (elastic beanstalk prefered)
  • Conditional injection of a service in AngularJS
  • Filtering on object properties not working
  • Open $modal from the service and pass variables to the controller
  • ngClick evaluated against scope instead of isolateScope
  • onEnter and onExit are not called when state is left/activated in angularjs ui router
  • Shared client & server modules with angularjs and pongular
  • Getting the angular app to run when using protractor
  • Angularjs: create a link for download different types of file
  • AngularJS: On Change of Parent DropDown Option Also Changes the Dependant Drop Down Options Associated with Other Parent
  • Angular HTML5 mode, Wordpress, Rewrites, Apache and You
  • Using angular js form validations in <form:input> tag
  • AngularJS call common functions in a directive template
  • AngularJS Promise resolved incorrectly
  • properly clearing whole AngularJS ui-grid chart
  • Can not figure out how to store $rootScope in angular.bootstrap
  • animate.css animation within angularjs 1.3 using ngAnimate gives different animations in Firefox
  • Auth0 IE Issue: Unable to get property 'frames' of undefined or null reference
  • Use an Angular JS value as a parameter of TWIG "path" function in Symfony 2
  • multiple function on ng-click angularjs
  • Converting $.ajax call to $http call in angular 404 error
  • Angularjs templateUrl file location not found
  • How to execute the function after change page in angularjs?
  • Pass variable to AngularJS directive without isolated scope
  • OAuth, Custom Login, or Both
  • Angular Directive: Isolate Scope & Transclude is true, but HTML in the directive needs to continue to bind to parent
  • Compare objects in angularjs
  • Combine "Checkbox" & "Avatar" in an Ionic Framework List
  • Issue with the Angular UI router when inheriting from a parent state
  • Is there a way to initialize an Angular Service without DI into controller
  • Why is a parent controller's $scope not accessible from a (child) directive?
  • How to get back button in Ion-tabs page
  • AngularJS bind class attribute to model
  • How can I get AngularJS ui-router to respond correctly to a browser page refresh?
  • Angular validation does not work
  • Breez Create Complex Entities
  • Drag and drop using protractor in dthmlx component
  • In Angular JS, what is the default 'cache' value that is used when sending request with $http service?
  • How to change placeholder for single textbox in angular?
  • $ is not defined - jquery angular mixing
  • CORS issue angularjs and spring security
  • Angularjs cannot select last item in dropdown the first time
  • Angularjs - $watch issue
  • On change radio button to no the span should hide in angular
  • Creating a wordcloud generator in Angularjs
  • Angular UI Bootstrap collapse - whats wrong?
  • AngularJS after redirect from app to app, the default page is not loading
  • Why does my scope update my factory and my factory update my scope when it should not?
  • AngularJS testing $httpBackend.whenGET().respond() not working with number as parameter
  • Setting up Login in Angular App
  • Retrieve value that is stored in db and display in select box using angularjs and laravel
  • Binding nested array in Angular view
  • Using filter with geojson, right direction?
  • Angularjs : mistake with $q
  • Apply logic to every element in an ng-repeat upon ng-click (AngularJS)
  • Directive within a directive fails to bind event
  • Header with image with ionic framework
  • What is the correct way to validate all form fields on submit when using ng-repeat for dynamic form?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org