I have just started learning typescript with angularjs from video tutorials. When I try to put angular module in my "app.ts" file which is by default the main file in backend. Here is my app.js code:
/// <reference path="Scripts/typings/jquery/jquery.d.ts" />
/// <reference path="Scripts/typings/angularjs/angular.d.ts" />
console.log("This is a TS file");
angular.module('classProjectApp', ['ngRoute'])
.config(function ($routeProvider) {
console.log("in Config()");
});
I have added angularjs file in my index.html file which goes like:
<html lang="en">
<head>
<meta charset="utf-8" />
<title>TypeScript HTML App</title>
<link rel="stylesheet" href="app.css" type="text/css" />
<script src="app.js"></script>
<script src="Scripts/angular.js"></script>
<script src="Scripts/angular-route.min.js"></script>
</head>
<body>
<h1>TypeScript HTML App</h1>
<div id="content"></div>
</body>
</html>
Despite this I am getting an error
Uncaught ReferenceError: angular is not defined
although the same example in video tutorial works fine.
PS when adding references in index.html file for angular I had to put relative path(Scripts/.../.../angular.js) while in video tutorial example just referenced it using "angular.js".
Thank You.
angularjs
reference to top app.js
should go to below. ng-app="classProjectApp"
on html
tag. try this below code instead of your code
<html ng-app="classProjectApp" lang="en">
<head>
<meta charset="utf-8" />
<title>TypeScript HTML App</title>
<link rel="stylesheet" href="app.css" type="text/css" />
<script src="Scripts/angular.js"></script>
<script src="Scripts/angular-route.min.js"></script>
<script src="app.js"></script>
</head>
<body>
<h1>TypeScript HTML App</h1>
<div id="content"></div>
</body>
</html>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.