tri___ton tri___ton - 3 months ago 25
Javascript Question

Angular controller directly in index.html

I need to make a one page app without any additional files like app.js or controller.js

I created the example below, but I get the error:

Module 'myApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

<!DOCTYPE html>
<meta charset="UTF-8">
<title> JavaScript Angular</title>
<script src="">

var myАpp = angular.module("myАpp", []);

myАpp.controller("firstController", function($scope){
$scope.test = "test-to-test";


<body ng-app = "myApp">
<div ng-controller = "firstController">


So, is it possible to have only one file index.html with Angular and still have a controller inside?


You need to have the controller and module inside the <script> tag

<div ng-app="myАpp">
  <div ng-controller="firstController">
<script src=""></script>
var app = 
    angular.module('myАpp', []).controller('firstController', function($scope){
  $scope.test  =  "test-to-test";