gpt4 book ai didi

javascript - Angular Js ng-controller 未填充该值

转载 作者:行者123 更新时间:2023-12-03 07:43:15 26 4
gpt4 key购买 nike

这可能与之前提出的问题重复,但请提供解决方案。我从头开始学习 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"
};
}

此后我无法从 Controller 获取动态值。

最佳答案

它不起作用,因为您使用的是 Angular 的默认“应用程序”。

首先您创建应用程序。在你的“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"
};
});

然后将应用程序插入您的 html 代码中:

<html lang="en" ng-app="appName">

关于javascript - Angular Js ng-controller 未填充该值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35317585/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com