Angular Js ng-controller没有填充该值
Angular Js ng-controller is not populating the value
可能是
之前提出的问题的副本,但请提供解决方案。我开始从头开始学习 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>
和应用程序.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"
};
}
在此之后,我无法从控制器获取动态值。
它不起作用,因为您使用的是Angular的默认"应用程序"。
首先创建应用。在您的"应用程序.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"
};
});
然后在您的 html 代码中插入应用程序:
<html lang="en" ng-app="appName">
相关文章:
- spine.js在启动时填充模型实例
- Fabric.js-更改矩形填充
- 在EXT窗体面板中填充EXT JS存储
- 使用kendo js填充网格
- 如何在js中实现树结构类型的表单动态填充
- 如何在d3.js中填充svg圆圈内的图像
- 在Angular JS中,预先填充ng中的下拉值repeat
- 在Sails.js中通过关系填充多对多
- 在Angular JS中填充对象以进行插入
- 在 Node.js 中填充来自猫鼬的对象
- JS使用不同的填充
- 意思是.JS中间件中的猫鼬填充不起作用
- 设置图像以使用纸张.js填充画布
- 面积图的条件填充 D3.js
- 如何以类似于vivus.js的样式设置SVG填充和路径的动画
- 在刀片模板中填充js数组
- 用PHP填充JS代码段
- PHP:使用opendir填充JS幻灯片
- 在特定索引中填充JS数组
- 如何在我的谷歌浏览器扩展程序中将信息从后台传递.js到自动填充.js