这可能是上一个问题的副本,但请提供解决方案。 我从头开始学习Angular Js,所以请帮助我们获得正确的价值。
我的HTML代码
<!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>
app.js文件是
var HeaderCtrl = function($scope){
$scope.appDetails = {
title: "BooKart",
tagline: "We have 1 million books for you"
};
}
var testController = function($scope){
$scope.appTest = {
title : "testTitle"
};
}
在此之后,我无法从控制器获取动态值。
答案 0 :(得分:1)
它没有用,因为您使用的是默认的&#34; app&#34; Angular。
首先创建应用。在你的&#34; app.js&#34; :
/*
* 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"
};
});
然后在您的HTML代码中插入应用程序:
<html lang="en" ng-app="appName">