Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'd like the buttons in my app to give feedback, as for example demonstrated here.
I'm wondering how I should structure my code. I want to be able to change the classes, the text and maybe disable them upon click. I guess a directive is the right fit, but the exact changes that will happen depend upon the button, and putting content or class names inside a controller or directive doesn't seem very right.
Right now i have a very generic directive that takes all options through additional attributes, but I wonder if someone can see a better way of doing it?
Always start with a very simple directive and extend with CSS classes. If you want to do a particular work well anything you can use a function of the controller. I think you made the right choice. Think to look angular UI for best practice : http://angular-ui.github.io
You can add event on each action:
// Create a new instance of ladda for the specified button
var l = Ladda.create( document.querySelector( '.my-button' ) );
// Start loading
l.start();
// Will display a progress bar for 50% of the button width
l.setProgress( 0.5 );
// Stop loading
l.stop();
// Toggle between loading/not loading states
l.toggle();
// Check the current state
l.isLoading();
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
How to handle dynamically changing ID's on refresh?
It's very common question but i would like to answer this question.
If id's are dynamic the you can go with any other locator techniques which ever is suitable in case of your app.
e.g. Name , className.
Mostly use of advance css or Xpath should work in your case. but you need to find unique set of properties / attribute values to locate.
Keep this in mind - just ignore on the part which is changing...focus on the part which is not changing and try to use that in any locator you choose.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
As an angularjs developer i want to know when i should use attribute versus an element
AS per my understanding and development knowledge Use an element when you are creating a component that is in control of the template. Use an attribute when you are decorating an existing element with new functionality.
But i am not sure ... please suggest
Angular directive documentation
Original answer by ckruszynsky:
The angular guidance says that you should use the "element"
restriction whenever the directive has full control over it's template
meaning it has a template that it is rendering out, etc.
For attributes, they suggest to use these only when you are adding
"behavior" to an existing element or decorating an existing element.
For example, think of the ng-click directive, this is used a attribute
not as a element because the click directive is just adding the click
behavior to some element.
Another example would be the ng-repeat directive, it is also used as
an attribute not as a element because it is going to repeat the
element in which it is being used in.
Now, this guidance is from the angular documentation; however, I don't
know necessarily that element vs. attribute is going to give you a
"better" approach it's more of a convention.
Now if you have to support older browsers, then you may want to
consider using either the comment or class directives.
My personal preference is to just use the attribute restriction;
mainly because people that are new to angular get overwhelmed at first
when they see the restrict and it's variations of the options that can
be used.
This question is quite opinion based, personnaly i use only attributes but i'm probably not the one to follow
However i can address some points following how HTML is designed :
element fits for a component (like an input, table).
attributes fits for options that influence the behaviour of your component (like type="text"). But they can be used as components too, as long you don't use two of them in the same element.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I've been searching online but all the top results on Google only lead me to Java. This is frustrating.
What I want to do is: make a program that listens to keyboard events, without being the active program. It has to work on at least windows 7, using C.
For example lets say I have myprogram.exe and other.exe. I want to be able to run both of them simultaneously, and have focus on other.exe, then press keys, and have myprogram.exe which runs on the side display which keys I pressed and log them.
If somebody has a link to a guide or information that explains what I should use to make this, that would be grand. If you can write up an explanation yourself that would be even better, but I don't mind going through documentations as long as they're relevant.
I've written games in C that listen to input from the active window, but I'm not sure how to poll events when the window isn't focused.
If you want to detect 'key press' events occurred in other processes, you should implement Global Hook. You can define a callback function for keyboard input events using SetWindowsHookEx().
Note that the callback function must be in a DLL in order to make it Global Hook.
So your myprogram.exe should link a dll implementing the hook. Then myprogram.exe would be able to detect any keyboard events on Windows.
Following is a good example with an explanation.
http://www.codeproject.com/Articles/1264/KeyBoard-Hooks
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I can't find any documentation on ng:click. My todo list application does not work unless I use ng:click as opposed to ng-click, yet I can't find any documentation on it. Is it the same as ng-click?
From the docs here: http://docs.angularjs.org/guide/directive
The normalization process is as follows:
Strip x- and data- from the front of the element/attributes. Convert
the :, -, or _-delimited name to camelCase.
So, angular interprets all of these as ngClick and then runs the directive named ngClick.
<button ng:click="myFunc()">ng:click</button>
<button ng-click="myFunc()">ng-click</button>
<button ng_click="myFunc()">ng_click</button>
See this live demo (click).
This being, your issue must be with your usage, which is not included. As this post is asking "What is the difference" and you have been answered that there is none, you might want to make a new post concerning the issue with your code and include your code.
Update based on your comment:
There are so many problem with your code that it would be unreasonable to go into depth about all of them. I'll give you some starting points for study.
First, here's a live demo of your code as it ought to look: http://jsbin.com/arAkuZo/6/edit
The "br" tag is deprecated and should no longer be used. Use css for that.
Your angular version is far out of date.
Don't use the global syntax for angular. Make a module and add your controller, etc to it.
There are several directives like `ngModel` that you seem to be unfamiliar with.
camelCase is the accepted standard for variable naming and Angular emphasizes it, so make it a note to use camelCase always. (at least almost always).
Yes, they're the same thing. Read http://docs.angularjs.org/guide/directive and http://docs.angularjs.org/guide/ie.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
this is probably a stupid question but here it goes anyway. I know that services are like singleton that's good for storing shared data. However I've been struggling with some concepts - Is it true that when using built-in directives like ng-repeat, do we always have to write "middle-man" methods to access/manipulate the shared objects in services? E.g
we have
appModule.service('fruits', function(){
this.items = ["apples", "bananas"];
});
To use ng-repeat to access these items, we must first need to write controller method like
appModule.controller("fruitsController", function($scope, fruits){
$scope.getFruits = function(){ return fruits.items;}
});
How about using custom directives then? Given that the service can also be injected into a directive, it will have direct access to the service. Is there any pros and cons of either methods?
So I think you're asking "Why not use custom directives for everything instead of controllers?"...
Well, basically because that would be harder to test. It's sort of like asking "Why separate code at all?".
The purpose of a directive is to provide two way access between your model and your view (the DOM) and handle setting up those interactions.
The purpose of a controller is to encapsulate "business logic" for the app.
Can you mix them both into a directive? Yes. Should you? Probably not.