1

I( have an MVC 5 application that is also using angularjs and boot strap. When the page loads the modal doesnt launch and i get the following err in the console:

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.2.8/$injector/modulerr?p0=myApp&p1=Error%3A%2….c%20(http%3A%2F%2Flocalhost%3A60248%2FScripts%2Fangular.min.js%3A17%3A431)

Here is my html:

Layout:

<!DOCTYPE html>
<html ng-app ="myApp">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Temujin @ViewBag.Title</title>

<link href="~/Content/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="~/Content/Site.css" rel="stylesheet" type="text/css" />
<script src="~/Scripts/modernizr-2.6.2.js"></script>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="~/Scripts/angular.min.js"></script>
<script src="~/js/Login.js"></script>
</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("Temujin", "Index", "Home", null, new { @class = "navbar-brand" })
        </div>
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
            </ul>
        </div>
    </div>
</div>

<div class="container body-content">
    @RenderBody()
    <hr />
    <footer>
        <p>&copy; @DateTime.Now.Year - Temujin</p>
    </footer>
</div>


</body>
</html>

Directive template:

<div class="modal fade">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h4 class="modal-title"></h4>
        </div>
        <div class="modal-body">
            <form class="form-signin" name="authForm" ng-submit="auth()" ng-controller ="AuthController" novalidate>
                <input type="text" class="form-control" placeholder="user name" ng-model ="AuthController.user.username" required autofocus>
                <input type="password" class="form-control" placeholder="password" ng-model ="AuthController.user.password" required>
                <input type="submit" class="btn btn-primary" value="Submit" />
            </form>
        </div>
    </div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->

cshtml:

@{
ViewBag.Title = "Login";
Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2></h2>
<div id="loginBox">
  <auth-modal></auth-modal>
</div>

angularjs:

(function () {
    var temujin = angular.module('temujin', []);

    temujin.controller('AuthModalController', ['$scope',function ($scope) {
    $scope.temujin.user = {};
    console.log("AuthModalController ran");
    $scope.$(".modal").modal({ message: 'HEll0 World' });
    }]);

temujin.directive("authModal", function () {
    return { restrict: 'E', templateUrl: '\\js\\templates\\auth-modal.html', controller: 'AuthModalController',controllerAs: 'authmodalCtrl'}
});

temujin.controller('AuthController',['$scope',function ($scope) {
    $scope.user = {};
    console.log("AuthController ran");
    $scope.auth = function () {
        console.log("user " + this.user);

    };
}]);
})();

MVC 5 controller:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace temujin.Controllers
{
public class TemujinController : Controller
{
    //
    // GET: /Temujin/
    public ActionResult Index()
    {
        return View();
    }
}
}

1 Answer 1

2

You are attempting to use the module myApp in your page here:

<html ng-app ="myApp">

But your actual module is named temujin

You just need to change your ng-app directive to point to the right module name.

<html ng-app ="temujin">
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.