0

Might be this is the duplicate of Previous asked question but please provide the solution. I started to learn the Angular Js from scratch, So Please help to get the correct value.

My HTML Code is

    <!doctype html>
<html lang="en" ng-app>
    <head>
        <meta charset = "utf-8">
        <title>Angular Js Test</title>
        <link rel="stylesheet" href= "bootstrap.min.css"/>
        <script src= "angular.min.js"></script>
        <script src="app.js"></script>
    </head>
    <body>  
        <div ng-controller="testController">
            {{appTest.title}}
        </div>

        <div id="header-wrapper" ng-controller="HeaderCtrl">
            <span class="logo pull-left">{{appDetails.title}}</span>
            <span class="tagline pull-left">{{appDetails.tagline}}</span>
            <div class="nav-wrapper pull-left">
                <ul class="nav nav-pills">
                    <li class="active"><a href="#">Books</a></li>
                    <li><a href = "#">Kart</a></li>
                </ul>
            </div>
            {{appDetails.title}}
        </div>
        <!--<p>Welcome to Bookart, we have collection of {{numofBooks + ' Million'}} books. </p>
        <input ng-model="numofBooks"/>
        <date-picker></date-picker>
        <div class="date-picker">test</div>-->
    </body>
</html>

And app.js File is

    var HeaderCtrl = function($scope){
    $scope.appDetails = {
        title: "BooKart",
        tagline: "We have 1 million books for you"
    };
}

var testController = function($scope){
    $scope.appTest = {
        title : "testTitle"
    };
}

After this I am not able to get the dynamic value from controller.

SaviNuclear
  • 886
  • 1
  • 7
  • 19
  • Use controller syntax. `angular.module('app').controller('headerCtrl', function($scope) {` – Tushar Feb 10 '16 at 14:18
  • currently you are following old way of doing controller initialization.. you should look at [this answer](http://stackoverflow.com/a/28728380/2435473) detailed answer – Pankaj Parkar Feb 10 '16 at 14:19

1 Answers1

1

It doesn't work because you are using the default "app" of Angular.

First you create the app. In your "app.js" :

/*
 * CREATING THE APP
 * you will use "app" to create controller, services, directives etc...
 * 'appName' is the name of your app, it will be in the <html> tag
*/
var app = angular.module('appName', []);
/*
 * CREATING THE CONTROLLER HeaderCtrl
 * 'HeaderCtrl' the name of the controller
 * function($scope){} is the implementation
*/
app.controller('HeaderCtrl', function($scope) {
    $scope.appDetails = {
        title: "BooKart",
        tagline: "We have 1 million books for you"
    };
});
/*
 * CREATING THE CONTROLLER testController
*/
app.controller('testController', function($scope) {
    $scope.appTest = {
        title: "testTitle"
    };
});

Then Insert the app in your html code :

<html lang="en" ng-app="appName">
Pokerface
  • 41
  • 4