Find related directive to element - angularjs

I'm just curious but I was wondering if there was a way to target an element and grab it's controlling directive. ie. something like angular.element('#id').directive().
If there's no direct way of doing this, I have a backup but I think it would be rather neat.
Thanks.

I think I may have posed the question incorrectly and confused people. All I was looking for was the .scope() method which you can call off an angular.element() selection. Seems to work nicely.

Related

How to fix an "structurally singular" - error in a simple loop model (Dymola)?

My Problem is maybe a rather simple one. I want to build up a simple Model of a Flettner Rotor. So it is just a fixed SupportStructure with a Motor/Revolute (fixedBearing) on top, that spins a hollow cylinder around it. At the Bottom there should be a loose fit, which i am not able to model...
On the attached pictures you can see the built up model and an animation of it. It is possible to simulate it without the "RevolutePlanarLoopConstraint".
I have to connect both structures again to model a second loose bearing. Because you have to create a loop, i tried all joints and constraints like "RevolutePlanarloppConstraint". In my opinion it should work ;)
No matter in what combination, i wasnt able to built up this connection. There is always the same error...(picture)
I cannot use the Rotor1D or something else, because i want to replace the bodys with existing discretized beam models later.
I think it is a typical problem of a locational/loose bearing combination, and i hope one of you has maybe a simple solution for it:)
Sadly i dont have the reputation to post images...
Kind regards
Paul

Making an angular statusbar directive

im looking to implement a directive to display status messages in my ionic angular app.. the idea is that i define a bunch of standard status messages in my template as follows and it's inspired by the stock ng-switch directive..
<status-bar code="statusCode" onShow="onStatusShow" onHide="onStatusHide">
<status-message when-code="OK" style="calm" timeout="3000">My HTML message</status-message>
...
...
<status-message when-complex style-field="style" text-field="text" timeout-field="timeout" />
</status-bar>
my requirements are these:
status-bar
the directive should bind to $scope.statusCode and depending upon its string value, it should activate one of the sub-directives except the when-complex one..
however, if i assign an object to $scope.statusCode, it should activate the when-complex directive if defined..
the directive also exposes an onShow and onHide callbacks..
when changing the value of $scope.statusCode, the previously active sub-directive should be completely hidden before showing the newly active one.. (animations)
status-message
style and timeout attributes are optional and will default to 'stable' and null respectively..
the timeout attribute will cause this sub-directive to show for a short time before clearing $scope.statusCode..
whereas i can write very simple directives, this one is proving to be a bit beyond me.. ive seen the source of ng-switch and its confusing.. i have tried myself as well but i havent gotten really far with this no matter how much ive tried.. im not posting my code approaches here not for the lack of trying but for the sake of cluttering and relevance..
so i was wondering if maybe someone could come up with a possible basic approach on codepen or plunkr that i can use as a base for expanding upon (since this is just a simplified explanation of what i intend to do with this directive).. or atleast point in the directions i need to go in..
after a night of brain-storming and coding punctuated by coffee and smoke breaks.. ive managed to make it work.. once again keeping ng-switch as a base.. the code is a bit long.. and i changed a few requirements along the way for better usability.. and some requirements like #2 and #3 dont work yet.. but im pretty sure ill make it work as well..
so if anybody is having a similar issue or is interested in my solution.. i can post it here.. :)

Angular $resource: update self from get

Is there any built-in method or conventionally correct approach to this? I'm not asking about issuing an update, but rather, requesting one. I could query for it again, but the goal is that the object reference stay the same.
The approach I've taken so far is to define an instance method called "refresh" that gets the same resource instance by ID and then iterates over its properties, copying them over to the original object (how I love thee _.extend). But it seems like something that might already be included functionality in ngResource and I just can't find it. If not, does Angular provide a means to make such a "refresh" method default to all $resources the same way save, delete, etc already are?
So I actually found the answer as I was writing the question, but I'm going to post it and answer anyway in case it might help someone else.
While writing that and looking stuff up, I realized that get is not restricted to being a static method of the resource. What threw me here was that on an instance, it's named $get. And lo, $get does exactly what I wanted. However it does not seem to be documented on Angular's site -- in fact the site says that only non-GET actions are instance methods, so who'd have thought? I mean, aside from that it seems totally obvious now.

AngularJS and ui-sortable(branch 1.2): ng-mouseover breaks after sorting

I upgraded my App to AngularJS 1.2 and so also switched to ui-sortable v 1.2.
The sorting is implemented for Accordion-Groups (from ui-bootstrap). With the master-tree version of sortable i could listen to ng-mouseover/ng-mouseleave inside the accordion headers but with the 1.2 version, the mouseevents are only listening as long as i haven't done any sorting. After performing any change to the sortorder, the mouseevents become deaf...
Here's a Plunker: http://plnkr.co/edit/n8yms9pb7uJp77zZ9LFK?p=preview
Can anybody give me some advice how to fix that?
Thank you
Identity Problem.
elementInsertedByDropping !== elementSelectedAndDragged
In the console, one can verify the assertion above. So that narrows down the category of problem to a relatively familiar one.
I'm learning Angular myself, and I'm also having trouble with ui-sortable; please don't regard my opinions as definitive. However, I believe that the problem is that the $watch listeners need to be re-bound to the new element, as it is being created asynchronously outside of Angular.
The "ng.$rootScope.Scope" documentation describes this situation somewhat clearly in the $apply section. If I am correct, you would need to either $scope.$apply(...) code in your controller, or [preferably] write a custom directive that handles the insertion.
Fortunately, it seems that jQuery-ui-sortable's "update" event can be easily used in a custom directive to ensure that the element is bound. I found that bloggers respectTheCode and Michal Ostruszka discuss the problem of writing jQuery-ui-sortable directives in fairly clear terms; so does a fellow named Greg Gigon and several others, but I'm only allowed to offer you two links at this point.
If I can provide more precise information at a later point, I will revise this answer; I'm still learning this stuff myself, and I would like to know how to do something quite similar.
[edit: I'm not familiar enough with Angular-UI-Sortable to know whether this is a bug or simply missing functionality.]
Looks like a bug in ui-sortable.
My guess: It seems to be losing the bindings from the event directives, probably because it's destroying the old DOM elements and creating a new ones without re-attaching the scope with $compile. I'd save this plunk and submit and issue on their GitHub repository

How to process a template and remove all bindings from it?

I need to create a page with AngularJS that will display thousands of log entries. These entries will be created with the help of Angular templates, but, since they are unchangeable once printed, I would like to have the bindings removed from the resulting entries.
Is this possible? I looked at $compile (keeps the bindings) and $interpolate (doesn't do directives if I understood correctly, only does {{ }} ) and haven't found an answer to my question.
How would you approach such a problem?
You can use the directives defined in the Bind Once library in order to perform binding for immutable data.
I didn't find an answer to my problem, the problem though can be circumvented with an "infinite scroller" such as the one described here: https://medium.com/p/463bc649c7bd that "disappears" log entries that aren't in the viewable window.

Resources