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.

2
  • Use controller syntax. angular.module('app').controller('headerCtrl', function($scope) { Commented Feb 10, 2016 at 14:18
  • currently you are following old way of doing controller initialization.. you should look at this answer detailed answer Commented Feb 10, 2016 at 14:19

1 Answer 1

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">
Sign up to request clarification or add additional context in comments.

2 Comments

With your help also it is not working...:(
Let me see your new files... Are the links to your javascript files correct?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.