0

I create controller and html page.

'use strict';
angular.module('myApp.view3', ['ngRoute'])

    .config(['$routeProvider', function($routeProvider) {
        $routeProvider.when('/view3', {
            templateUrl: 'view3/view3.html',
            controller: 'View3Ctrl'
        });
    }])

    .controller('View3Ctrl', [function($scope) {
        $scope.my_name = "Pasha";
    }]);

and it is my html page.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>My view</title>
</head>
<body>
<p> Hello Pavel</p>
<div>{{my_name}}</div>
</body>
</html>

I want show in browser my html.

Hello Pavel

Pasha

Angular seed app: v0.1

But I see in browser

 Hello Pavel
 {{my_name}}   
 Angular seed app: v0.1    

I use example from link

EDIT: I add appjs.

It is my app js file my file it is my file:

'use strict';

// Declare app level module which depends on views, and components
angular.module('myApp', [
  'ngRoute',
  'myApp.view1',
  'myApp.view2',
  'myApp.view3',
  'myApp.version'
]).
config(['$routeProvider', function($routeProvider) {
  $routeProvider.otherwise({redirectTo: '/view1'});
}]);
6
  • there is no controller named View3Ctrl in your html Commented Feb 1, 2016 at 9:33
  • what????????????????????????????? Commented Feb 1, 2016 at 9:36
  • I don't see this module myApp.view3? Do you really have it? Like <html lang="en" ng-app="myApp"> Commented Feb 1, 2016 at 9:36
  • I edit quation............. Commented Feb 1, 2016 at 9:38
  • <html lang="en" ng-app="myApp"> - not work Commented Feb 1, 2016 at 9:42

2 Answers 2

2
  1. Add ng-app and ng-controller to your body
  2. Add '$scope' in the controller

'use strict';
angular.module('myApp.view3', [])

    .controller('View3Ctrl', ['$scope', function($scope) {
        $scope.my_name = "Pasha";
    }]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>My view</title>
</head>
<body ng-app="myApp.view3" ng-controller="View3Ctrl">
<p> Hello Pavel</p>
<div>{{my_name}}</div>
</body>
</html>

Sign up to request clarification or add additional context in comments.

7 Comments

why this answer is not worked for you @ user5620472? could you explain please?
It is worked but I think it incorect. I config views in app.js file and include to index.html. I think I not need Include <script src="ajax.googleapis.com/ajax/libs/angularjs/1.2.23/…> to each html file or I wrong?
@user5620472 No need to include the script tag in each html file. This is was included to make the piece of sample script to work.
I was think if I include .config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view2', { templateUrl: 'view2/view2.html', controller: 'View2Ctrl' }); }]) I not need write controller name in html page and it mapped automaticly
You are right. View3Ctrl will be available in view3.html
|
0

HTML

<div ng-controller="View3Ctrl as ctrl">{{ ctrl.my_name}}</div>

You also need to set your documents ng-app attribute. See more in the docs.

2 Comments

It is not work! browser show - {{ctrl.my_name}}(<div ng-controller="View3Ctrl as ctrl">{{ctrl.my_name}}</div>)
have you set the ng-app?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.