Angular application runs via bootstrap:

<script> angular.bootstrap(document.getElementById('div_app'), ['demo']); </script> 

The controller code must be in a separate js file.

 app.controller('MainCtrl', ['$scope', 'val', function($scope, val) { $scope.new = 'New ' + val; }]); 

You need to set the value for the application in the script container inside the html. Sort of:

 var app = angular.module('demo', []).value("val", "World"); 

Plunker example

  • uh, everything seems to work in a planker, can you elaborate a question? - Grundy
  • In the planker, the value is set in the js file, and you need it in the script container inside html - Browen
  • So? plunkr - Grundy
  • So . Thank . - Browen
  • @NicolasChabanovsky, added, but it seems to me that this is more appropriate for the reason: not reproduced or a typo - Grundy

1 answer 1

Nothing prevents to make the creation of a module in a separate script

 <script> var app = angular.module('demo', []).value("val", "World"); </script> 

The main thing is to connect it before the main code file.
Plunkr example

In addition, you can not save the resulting module in a variable.

 <script> angular.module('demo', []).value("val", "World"); </script> 

In this case, in the main script you need to add the line for receiving the module

 app = angular.module('demo'); //ΠΎΠ±Ρ€Π°Ρ‚ΠΈΡ‚Π΅ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅ Π½Π° отсутствиС списка зависимостСй. app.controller('MainCtrl', ['$scope', 'val', function($scope, val) { $scope.new = 'New ' + val; }]);