I'm new to Angular but I've done a couple basic examples successfully. Now I'm looking at starting my first real world Angular/MVC/WebAPI app. It's going to be a Time Card type app and the first thing I'm looking to do is display the current time of the local user. I did to a basic HelloWorld with Angular on the Index.cshtml page just to make sure my references to Angular were correct. That worked....BTW, I'm using Angular v1.5.
I found the following post and I'm trying to use a mixture of the code.
http://www.codeproject.com/Articles/806029/Getting-started-with-AngularJS-and-ASP-NET-MVC-Par
http://stackoverflow.com/questions/23383233/how-to-make-a-ticking-clock-time-in-angularjs-and-html
However I'm not getting it to work and it's probably something simple I'm missing, yet I don't see it.
Here is my _Layout.csthml. I have the ng-app and ng-controller listed in the
<html> tag
<!DOCTYPE html>
<html ng-app="VirtualTimeClockApp" ng-controller="LandingPageController">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title</title>
@Styles.Render("~/Content/css")
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
@Html.Partial("_LoginPartial")
</div>
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© @DateTime.Now.Year - My ASP.NET Application</p>
</footer>
</div>
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/bundles/angular")
@Scripts.Render("~/bundles/VirtualTimeClockApp")
@RenderSection("scripts", required: false)
</body>
</html>
Here is my Home/Index.cshtml
@model VirtualTimeClock.ViewModels.HomeViewModel
@{
ViewBag.Title = "Home Page";
}
<div class="jumbotron">
<h1>@Model.currentServerTime</h1>
<div ng-controller='TimeCtrl'>
<p>{{ clock | date:'HH:mm:ss'}}</p>
</div>
<p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
<p><a href="http://asp.net" class="btn btn-primary btn-lg">Learn more »</a></p>
</div>
Here is my BundleConfig.cs file. Next to the last Bundles.Add is where I bundle the controller directory and the main .js file.
namespace VirtualTimeClock
{
public class BundleConfig
{
// For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js"));
bundles.Add(new ScriptBundle("~/bundles/angular").Include(
"~/Scripts/angular.js"));
bundles.Add(new ScriptBundle("~/bundles/VirtualTimeClockApp")
.IncludeDirectory("~/Scripts/Controllers", "*.js")
.Include("~/Scripts/VirtualTimeClock.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
}
}
}
This is my VirtualTimeClock.js file. The thing I'm not 100% on here is the declaration of VirtrualTimeClockApp is then adding a module to the "VirtualTimeClockApp" that is referenced in the ?
var VirtualTimeClockApp = angular.module('VirtualTimeClockApp', []);
VirtualTimeClockApp.controller('LandingPageController', LandingPageController);
This is my LandingPageController.js file.
var module = angular.module('VirtualTimeClockApp', []);
module.controller('TimeCtrl', function ($scope, $interval) {
var tick = function () {
$scope.clock = Date.now();
}
tick();
$interval(tick, 1000);
});

LandingPageController.jsbeforeVirtualTimeClock.jsLandingPageControllerbut i do not see the function you are referring to. There should be afunction LandingPageController(){};in your code somewhere.I'm assuming the next property is the LandingPageController.jsis a wrong assumption. The second parameter is the function name, which you have not defined. Angular does not load JS files from controllers like that.