gpt4 book ai didi

javascript - 从 Angular Material 设计开始

转载 作者:搜寻专家 更新时间:2023-10-31 08:29:44 25 4
gpt4 key购买 nike

我已经尝试使用 Angular Material Design 一周了,但没有成功。我花了很多时间研究 HTML/CSS、JavaScript 和 AngularJS 以了解问题所在,但我仍然不知道问题出在哪里。

基本上我尝试的是 Google Angular Material Design“入门” 部分网站,但没有一个与我合作:

我试图复制它的 Github Starter Project但我得到了这个结果:

编辑:抱歉,我的帐户是新帐户,我还不能发布图片,但它是我网站的打印屏幕,甚至没有运行 Angular ![我的结果][3]。

我也曾尝试复制其简单的 Hello World 示例,但我遇到了非常相似的问题。

我不知道我做错了什么,但我认为这很简单。我感觉我没有导入正确的 CSS/JS。

var app = angular.module('StarterApp', ['ngMaterial']);

app.controller('AppCtrl', ['$scope', '$mdSidenav', function($scope, $mdSidenav){
$scope.toggleSidenav = function(menuId) {
$mdSidenav(menuId).toggle();
};

}]);
.menuBtn {
background-color: transparent;
border: none;
height: 38px;
margin: 16px;
position: absolute;
width: 36px;
}
md-toolbar h1 {
font-size: 1.250em;
font-weight: 400;
margin: auto;
}
md-list .md-button {
color: inherit;
font-weight: 500;
text-align: left;
width: 100%;
}
.visually-hidden {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}

/* Using Data-URI converted from svg until <md-icon> becomes available
https://github.com/google/material-design-icons
*/
.menuBtn {
background: transparent url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2ZXJzaW9uPSIxLjEiIHg9IjBweCIgeT0iMHB4IiB3aWR0aD0iMjRweCIgaGVpZ2h0PSIyNHB4IiB2aWV3Qm94PSIwIDAgMjQgMjQiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDI0IDI0IiB4bWw6c3BhY2U9InByZXNlcnZlIj4KPGcgaWQ9IkhlYWRlciI+CiAgICA8Zz4KICAgICAgICA8cmVjdCB4PSItNjE4IiB5PSItMjIzMiIgZmlsbD0ibm9uZSIgd2lkdGg9IjE0MDAiIGhlaWdodD0iMzYwMCIvPgogICAgPC9nPgo8L2c+CjxnIGlkPSJMYWJlbCI+CjwvZz4KPGcgaWQ9Ikljb24iPgogICAgPGc+CiAgICAgICAgPHJlY3QgZmlsbD0ibm9uZSIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0Ii8+CiAgICAgICAgPHBhdGggZD0iTTMsMThoMTh2LTJIM1YxOHogTTMsMTNoMTh2LTJIM1YxM3ogTTMsNnYyaDE4VjZIM3oiIHN0eWxlPSJmaWxsOiNmM2YzZjM7Ii8+CiAgICA8L2c+CjwvZz4KPGcgaWQ9IkdyaWQiIGRpc3BsYXk9Im5vbmUiPgogICAgPGcgZGlzcGxheT0iaW5saW5lIj4KICAgIDwvZz4KPC9nPgo8L3N2Zz4=) no-repeat center center;
}
<html lang="en" ng-app="StarterApp">
<head>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/angular_material/0.7.1/angular-material.min.css">
<link rel="stylesheet" href="CSS/test.css">
</head>
<body layout="column" ng-controller="AppCtrl">
<md-toolbar layout="row">
<button ng-click="toggleSidenav('left')" hide-gt-sm class="menuBtn">
<span class="visually-hidden">Menu</span>
</button>
<h1>Hello World</h1>
</md-toolbar>
<div layout="row" flex>
<md-sidenav layout="column" class="md-sidenav-left md-whiteframe-z2" md-component-id="left" md-is-locked-open="$media('gt-sm')">

</md-sidenav>
<div layout="column" flex id="content">
<md-content layout="column" flex class="md-padding">

</md-content>
</div>
</div>
<!-- Angular Material Dependencies -->
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-animate.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-aria.min.js"></script>

<script src="//ajax.googleapis.com/ajax/libs/angular_material/0.7.1/angular-material.min.js"></script>

<script src="JS/test.js"></script>
</body>
</html>
我尝试在 [brackets][4] 上重新创建这个确切的代码,但是当我在浏览器中运行它时,它不起作用。我的代码还需要做些什么吗?

最佳答案

我无法准确理解什么对您不起作用,但请注意,如果您从本地文件系统查看此页面,则需要指定 http://https:// 引用您的外部资源时。

目前您的所有 Assets 都被这样引用://ajax.googleapis.com/ajax/libs/angular_material/0.7.1/angular-material.min.css

这可能会阻止 Angular 和其他所有内容加载到您的页面中。

更多解释

如评论中所述,您使用的是 Protocol-relative URL .

If the browser is viewing that current page in through HTTPS, then it’ll request that asset with the HTTPS protocol, otherwise it’ll typically* request it with HTTP. This prevents that awful “This Page Contains Both Secure and Non-Secure Items” error message in IE, keeping all your asset requests within the same protocol.

文章还提到:

*Of course, if you’re viewing the file locally, it’ll try to request the file with the file:// protocol.

关于javascript - 从 Angular Material 设计开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28563701/

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