vendredi 24 juin 2016

Angular JS + Asp.Net MVC basic example; Angular not been refered [on hold]

I know this is the basic question, i tried to find a workaround and it works. But i want to know what i'm missing here.

I have created a sample application with Asp.Net MVC and angular, just tried to display a hardcoded text to MVC view from angular and its not getting displayed. I guess this happens as it couldnt find angular.js reference. I tried to view source and could find the reference.

In the later case i provided full path of Angular.js file and its working fine.

Code: BundleConfig.cs

    bundles.Add(new ScriptBundle("~/bundles/AMV_Angular1")
            .IncludeDirectory("~/Scripts/Controllers","*.js")
            .Include("~/Scripts/AMV_Angular1.js",
            "~/Scripts/Angular.js"));

Index.cshtml

<!DOCTYPE html>
<html ng-app="myApp">
<head>
    <title ng-bind="helloAngular"></title>
</head>
<body ng-controller="cnt">

    <input type="text" ng-model="helloAngular" />
    <h1>{{helloAngular}}</h1>

    @Scripts.Render("~/bundles/AMV_Angular1")
</body>
</html>

Javascript File

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

    myApp.controller("cnt", function ($scope) {
        $scope.helloAngular = "this is from Angular";
    });

}());

The below is output in HTML and Source of rendered HTML

enter image description here Below is my directory structure

enter image description here

Any help is appreciated. Thank you.

Aucun commentaire:

Enregistrer un commentaire