Я просто знаком с угловыми. Я пытаюсь проверить простой контроллер в моем index.html. Но когда я запускаю его на моем localhost, я получаю сообщение об ошибке:
Не удалось загрузить ресурс: сервер ответил статусом 404 (Not Found).
Вот моя структура папок:
angulartesting
-bower_components
-index.html
-//script.js
Вот мой файл index.html:
<!-- index.html -->
<!DOCTYPE html>
<html ng-app="store">
<head>
<!-- SCROLLS -->
<!-- load bootstrap and fontawesome via CDN -->
<link href="/bootstrap.min.css" rel='stylesheet' type='text/css' />
<!-- SPELLS -->
<!-- load angular and angular route via CDN -->
<script src="/angular.min.js"></script>
<script src="/angular-route.js"></script>
<script src="//script.js"></script>
</head>
<body >
<div ng-controller="StoreController as store">
<h1>{{store.product.name}}</h1>
<h2>${{store.product.price}}</h2>
</div>
<script src="/bootstrap.min.js"></script>
</body>
</html>
Вот мой //script.js:
// create the module and name it scotchApp
// also include ngRoute for all our routing needs
(function(){
var app = angular.module('store', []);
app.controller('StoreController',function(){
this.product=gem;
});
var gem = {
name:'Gaurav',
price:'220'
}
})();
Может ли кто-нибудь сказать мне, что я делаю неправильно?
Я запускаю его на своем локальном сервере.
Попробуй это. Я только что удалил косые черты перед источниками скрипта и добавил атрибут ng-app
.
<!-- index.html -->
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<!-- SCROLLS -->
<!-- load bootstrap and fontawesome via CDN -->
<link href="/bootstrap.min.css" rel='stylesheet' type='text/css' />
<!-- SPELLS -->
<!-- **Removed forward slashes before script sources** -->
<script src="/angular.min.js"></script>
<script src="/angular-route.js"></script>
<script src="//script.js"></script>
</head>
<body>
<div ng-controller="StoreController as store">
<h1>{{store.product.name}}</h1>
<h2>${{store.product.price}}</h2>
</div>
<script src="/bootstrap.min.js"></script>
</body>
</html>
Надеюсь, поможет