SIGforum.com    Main Page  Hop To Forum Categories  The Lounge    Any ASP.net MVC AngularJS gurus?
Go
New
Find
Notify
Tools
Reply
  
Any ASP.net MVC AngularJS gurus? Login/Join 
McNoob
Picture of xantom
posted
I support a host of WPF and web apps with differing technologies. I am a novice with AngularJS. I have tried a host of suggestions and other ways to get this to work but I cannot figure it out. I am sure I am just missing something obvious.

I just want to get this ng-click event to post a log to the console in chrome. Can someone tell me why this ng-click event will not fire?


Using VS 2015, ASP.net MVC Web Application.
These are the locations and contents of my cshtml and js files...

Views\Home\index.cshtml
@{
ViewBag.Title = "Home Page";
}


<div class="jumbotron">
<h1>File Uploader</h1>
<p class="lead">Upload up to 5 files with a max file size of 12mb per file.</p>

<!-- Upload -->
<section class="row thematic-wrapper">
<div ng-controller="Uploader" class="col-sm-12">
<label class="lbl">Upload Documents >>>> |</label>
<button class="btn" ng-click="UploadFile()" >
Test Button
</button>
</div>
</section>

</div>


Scripts\Uploader.js

'use strict'

$scope.UploadFile = function () {
$log.log("Welcome to Uploader.js!")
$console.log("Welcome to Uploader.js!")
}




I posted this on stackoverflow and lost 6 reputation??




"We've done four already, but now we're steady..."
 
Posts: 1873 | Location: MN | Registered: November 20, 2013Reply With QuoteReport This Post
Serenity now!
Picture of 4x5
posted Hide Post
I don't think your angular controller is set up properly. Bring up your Javascript console in your browser, and check if any errors are logged. Can you post your complete controller code?



Ladies and gentlemen, take my advice - pull down your pants and slide on the ice.
ʘ ͜ʖ ʘ
 
Posts: 4950 | Location: Highland, UT | Registered: September 14, 2006Reply With QuoteReport This Post
McNoob
Picture of xantom
posted Hide Post
This is the "out of the box" controller that I have. No errors in the console.





"We've done four already, but now we're steady..."
 
Posts: 1873 | Location: MN | Registered: November 20, 2013Reply With QuoteReport This Post
Serenity now!
Picture of 4x5
posted Hide Post




here is a very basic controller and view. These two files will work if you open index.html in your browser. Look at how the controller is defined. That's what you need to do in your code. Also look at index.html where ng-app is referenced near the top of the file. I think your sample was missing that.



Ladies and gentlemen, take my advice - pull down your pants and slide on the ice.
ʘ ͜ʖ ʘ
 
Posts: 4950 | Location: Highland, UT | Registered: September 14, 2006Reply With QuoteReport This Post
Serenity now!
Picture of 4x5
posted Hide Post
The 'out of the box' controller you just posted is actually an ASP. Net MVC controller, which is different than an angular controller. You want to look at your angular controller, which you named uploader.js



Ladies and gentlemen, take my advice - pull down your pants and slide on the ice.
ʘ ͜ʖ ʘ
 
Posts: 4950 | Location: Highland, UT | Registered: September 14, 2006Reply With QuoteReport This Post
McNoob
Picture of xantom
posted Hide Post
Thank you for your suggestions.

Ok I wasn't sure, that was my entire js file.

I can get ng-click to work in any plunker type editor. It's in Visual Studio that I can't make it work.

Here are my latest updates, still not working. No errors on build or in the console. Running in incognito to ensure it's not a caching issue...





"We've done four already, but now we're steady..."
 
Posts: 1873 | Location: MN | Registered: November 20, 2013Reply With QuoteReport This Post
Serenity now!
Picture of 4x5
posted Hide Post
Well, you are using ng-app twice... Once in the layout file, and again in the cshtm file. Try taking it out of the cshtm file. Are you getting any errors logged to the console?

I also don't see anywhere in your code where you're loading uploader.js. You have to load that file in one of your cshtml files. It also doesn't look like you're loading the angular files. Take a look at how I load angular in the sample code I posted. You need to add a line like that to your code, and also a line where you load the uploader.js file. Unless you're already loading them in one of your bundles.



Ladies and gentlemen, take my advice - pull down your pants and slide on the ice.
ʘ ͜ʖ ʘ
 
Posts: 4950 | Location: Highland, UT | Registered: September 14, 2006Reply With QuoteReport This Post
McNoob
Picture of xantom
posted Hide Post
Thank you so much for the help, it's working now! Cool





"We've done four already, but now we're steady..."
 
Posts: 1873 | Location: MN | Registered: November 20, 2013Reply With QuoteReport This Post
Serenity now!
Picture of 4x5
posted Hide Post
Glad to help. Let me know if you have anymore questions.



Ladies and gentlemen, take my advice - pull down your pants and slide on the ice.
ʘ ͜ʖ ʘ
 
Posts: 4950 | Location: Highland, UT | Registered: September 14, 2006Reply With QuoteReport This Post
  Powered by Social Strata  
 

SIGforum.com    Main Page  Hop To Forum Categories  The Lounge    Any ASP.net MVC AngularJS gurus?

© SIGforum 2024