How to set 'currentNavItem' default in the view - angular-material

I know its easy to do from the model, as done here:
http://codepen.io/next1/pen/yJaojP
function AppCtrl($scope) {
$scope.currentNavItem = 'page1';
}
but how would you do it from the view?

CodePen
Edit: In answer to your comment below you could use ng-init
<md-nav-bar md-selected-nav-item="currentNavItem" nav-bar-aria-label="navigation links" ng-init="currentNavItem='page2'">
However, it's worth noting in the ngInit docs the following:
You should be okay to use it though.

Related

WOW Addon commands

I'm learning about wow addons and I would like to create a command that shows in chat "Hello World" when I typed "/cht". I checked http://wowwiki.wikia.com/wiki/Creating_a_slash_command but my code does not work.
My code:
SLASH_CHAT = "/cht"
SlashCmdList["CHAT"] = function(msg)
print("Hello World!")
end
Do you have any idea why is not working?
Thanks in advance.
You need to change your global from SLASH_CHAT to SLASH_CHAT1, yes it's really that simple.
I've updated http://wowwiki.wikia.com/wiki/Creating_a_slash_command, fixing the examples and I added a simple starter example at the top with a condensed explanation of the mechanism and rules.
Some of the examples were unclear, but more importantly the actual rules for naming were fairly buried, which is where the OP was having issues.
The new top example reads:
SLASH_TEST1 = "/test1"
SLASH_TEST2 = "/addontest1"
SlashCmdList["TEST"] = function(msg)
print("Hello World!")
end
This was not totally your fault. :)
Before edit:
Same text as above basically, except I had misremembered and the code I used to spot check was complex and I misinterpreted it. I gave wrong information above on naming above (and edited the whole wiki article the same way). Both are fixed now. Comment below complaining was to the original answer I made here.

JSCS How to disable for a specific part of code rule requireDotNotation?

I am using JSCS to validate my code and I have requireDotNotation set to on for all my code base, but for a specific part of code I need to disable this rule.
Basically I would need to do something similar (example working for JSHint) but for JSCS:
/*jshint sub:true*/
//some code here
/*jshint sub:false*/
I was able to solve this issue using the following code:
//jscs:disable requireDotNotation
//some code here
//jscs:enable requireDotNotation
I am adding this answer hope can help others.

Is there in grails something like domainClass.addToAll? for one to many or many to many

do we have in gorm something like addAll method in groovy?, i mean something like
someDomainClass.addToAll***
No we do not. But it is easy to work around:
[child1, child2, child3].each { parent.addToChildren it }
This question has a good answer here Syntax for "addAll()" to list in grails?.
I don't know why a addAllToEntity wouldn't exist, but it wouldn't do much more then the loop mentioned in the answers (the one you got and the one I suggested), would it?

Rails: Hack/workaround: Is there a way to return/(stop execution) in the middle of a view?

EDIT: Please don't worry about best practice. I am looking for a hack on this. Again, I don't want to use this in a team. Thanks for understanding.
I have a view file called index.html.haml
- if this.that?
%div#if
....
....
- else
%div#else
....
....
But I want to do this:
- if this.that?
%div#if
....
....
- return
%div#else
.....
.....
Is this possible? Thanks
I know that it is not polite to answer a question with another one, but: Did you even try?
Sure you can! The code in ERB templates is evaluated as plain ruby and so you can use return in there as well. It is often required to return "something", like return ''.
It is not considered a "best practice" though, like #meagar already stated in the comments. Especially if you do it deep inside a template or partial. That is really bad style, your coworkers will hate you for that. A punch in the face is common in such situations.
Once a while i use return in partials when there is nothing to render like return if Rails.env.production? but that is rare and also pretty obvious when it's the first line in a partial.
After searching a bit into the haml source code I think what you are looking for is the following:
- return #haml_buffer.buffer
In case you need the same hack for .erb you should add
<% return #output_buffer %>
Putting one of the above in one of your view files it will "flush" out all the contents that have been concatenated to the buffer up to that point.
I don't think you really need a "hack" per se. You may just need the cells gem as this gives you a little cell with MVC in portion of the view you're rendering.
Most likely this will handle the Model-View-Presenter the way you are trying to. :)
I like the cells gem idea, but perhaps if you must, just include a
flash[:something] = this.that?
in the controller and use something to absorb that in a data-field somewhere in the dom for you to perform your logic via javascript.
:javascript
$(document).ready(function(){
var a = $("h1").data("that")
do something if a == ? like hide the else %div
})

ASP.NET MVC JavaScript Routing

Spoiler alert: this is NOW a question, so apologies to anyone that read it purely as a discursive topic :)
Anyway, I was doing a little research today re adding routes via javascript when i thought that a bit of google research wouldn't hurt. Basically, my aim was to do away with the following type of construct within my views:
and replace it with something akin to:
well, i lucked out a little today after finding this fantastic article (which isn't mine nor do i have any affiliation other than respect for the piece of work):
http://weblogs.asp.net/zowens/archive/2010/12/20/asp-net-mvc-javascript-routing.aspx
this really has been a missing link (or so i thought) for me when dealing with routes via javascript. However, the 2nd code example is misleading and actually won't produce what the example leads on. Can anyone suggest a fix for this and/or an alternative solution to allow this fluent convention of js routes within mvc views??
cheers...
[edit] - question edited 22:16 GMT to explore deeper options on this topic, plus changed title (removed OT portion).
So the question is why the second code example won't work as expected. Here's the answer, post currently doesn't return anything. This is an example of a certain developer not looking at the details of the code. When you use homePageUrl, the value will be undefined.
To actually get the home page URL, you'd do the following:
$.routeManager.action({controller:'Home', action:'Index'}).toUrl()
So, the moral of the story is that the code is a bit broken. The post action SHOULD return an object where you can put "toUrl()" right after the post is performed, like this:
$.routeManager.action({controller:'Home', action:'Index'})
.post(function(data){ alert(data); })
.toUrl();
I'll be fixing this bug in a bit!

Resources