我对Angular很新,而且我还在努力解决这个问题.我正在使用我从Yeoman Generator生成的Angular 1.5.8编写一些测试.
具体来说,我正在试图弄清楚如何操纵$ httpBackend结果(我不确定这是否重要)...
在我的app.js文件中,我有以下代码:
.run(['$rootScope', '$location', 'breadcrumbService', function ($rootScope, $location, breadcrumbService) {
$rootScope.$on('$viewContentLoaded', function () {
jQuery('html, body').animate({scrollTop: 0}, 200);
});
$rootScope.isEditMode = false;
$rootScope.$on('$stateChangeSuccess', function () {
// ------------ this next line is failing -----------
$rootScope.isEditMode = $location.path().toLowerCase().endsWith('/edit') || $location.path().toLowerCase().endsWith('/new');
});
$rootScope.parseJson = function (value) {
return angular.fromJson(value);
};
$rootScope.bc = breadcrumbService;
$rootScope.title = "";
}])
Run Code Online (Sandbox Code Playgroud)
大约一半的线(我添加评论的地方)失败了.具体来说,endsWith函数失败(toLower很好),出现此错误:
PhantomJS 2.1.1 (Windows 8 0.0.0) Service: breadcrumbService should return breadcrumb label in json format FAILED
TypeError: undefined is …Run Code Online (Sandbox Code Playgroud) 好吧,所以我一直在谷歌上搜索这个问题一段时间了,但我似乎无法找到一个好的单页面应用程序路由器所需要的东西.我想要的是:
那里有一个像这样存在的图书馆吗?我看着crossroads.js,看起来很棒,但它确实做了hashbangs/hashtags /哈希.我查看了Backbone.js,但它具有众多功能和6.5Kb大小,不太热衷.这个家伙当场得到了它,但他的图书馆似乎没有得到很好的支持.我对这个快速尝试感到非常惊讶,但它似乎并没有包括跨浏览器,或者得到很好的支持.还有数百个,但我不知道应该选哪一个?有没有其他人为单页应用程序提供这个相当简单的功能?
有时我被迫以编程方式将DOM样式添加到DOM中(如果您需要一个理由:想象一下编写一个带有自己样式的小UI小部件,但应该只包含一个*.js文件以便于处理).在这种情况下,我更喜欢使用对象表示法在我的脚本代码中定义样式,而不是使用混合规则,属性和标记的一个大字符串.
var thumbHoverStyle = {
"background-color": "rgba(211, 211, 211, 0.5)",
"cursor": "pointer"
};
Run Code Online (Sandbox Code Playgroud)
与
var thumbHoverStyle = "<style> .thumb:hover { background-color: rgba(211, 211, 211, 0.5); cursor: pointer; } </style>";
Run Code Online (Sandbox Code Playgroud)
这样的css-object可以很容易地与JQuery的.css()函数一起使用,但是一旦我想要设置一个css伪类(在我的例子中:hover),麻烦就开始了.在这种情况下,我无法使用JQuery .css()函数,我回过头来向我的DOM中插入相应的样式标记.
var thumbHoverStyleTag = toStyleTag( { ".thumb:hover": thumbHoverStyle } );
_root.append(thumbHoverStyleTag);
Run Code Online (Sandbox Code Playgroud)
我用google搜索和stackoverflowed但找不到将我的css-object转换为样式标记的实用程序函数.最后我编写了自己的函数(我可能会将它作为这个问题的答案),但我仍然想知道是否有一个库函数.实现这一目标的最优雅方法是什么?
编辑
我在TypeScript中的实现:
function appendPxIfNumber(value: any): string
{
return (typeof value === "number") ? "" + value + "px" : value;
}
function toStyleTag(rulesObj: any)
{
var combinedRules: string = "";
for (var selector …Run Code Online (Sandbox Code Playgroud) 您好,我在 scss 文件中有一些 scss 颜色定义:
$blue: #20a8d8;
$indigo: #6610f2 !default;
$purple: #6f42c1 !default;
$colors: (
blue: $blue,
indigo: $indigo,
purple: $purple
)
Run Code Online (Sandbox Code Playgroud)
并想在绘制 React js 图表时使用它们:
import React, { Component } from 'react';
import {CardColumns, Card, CardHeader, CardBlock} from "reactstrap";
import {Line} from "react-chartjs-2";
const dataA = {
labels: ['Week 1', 'Week 2', 'Week 3', 'Week 4'],
datasets: [
{
label: 'Number of Customers in Shop A',
fill: false,
lineTension: 0.1,
backgroundColor: red
}]
};
Run Code Online (Sandbox Code Playgroud)
我尝试使用“红色”作为背景颜色,但失败并出现错误:
Uncaught ReferenceError: red is …Run Code Online (Sandbox Code Playgroud) 根据文档,我们可以visibility: collapse在<col />元素上使用来折叠或折叠所有关联的列。
但是(在 Chrome 和 Edge 中)我注意到一些元素仍然可见,漂浮在折叠列将占据的区域的某个位置。我可以将其范围缩小到带有position: absolute或 的元素position: relative。这似乎是 Chrome 和 Edge 中的一个错误(均显示此行为)。在 Firefox 中,不会留下意外可见的痕迹。
const toggle = () => {
const table = document.querySelector("#my-table");
table.classList.toggle("collapsed");
};Run Code Online (Sandbox Code Playgroud)
.table.collapsed .collapsible-column {
visibility: collapse;
}
.oops {
position: relative;
}Run Code Online (Sandbox Code Playgroud)
<table id="my-table" class="table">
<colgroup>
<col span="2" class="collapsible-column" />
<col span="2" class="static-column" />
</colgroup>
<thead>
<tr>
<th scope="col">col 1<br /><span class="oops">oops</span></th>
<th scope="col">col 2</th>
<th scope="col">col 3</th>
<th scope="col">col …Run Code Online (Sandbox Code Playgroud)我关注了这篇文章如何在我的 React 组件中使用 SCSS 变量或这个React 和 SCSS 从 scss 导出一个变量以做出反应以在我的 React 应用程序中获取 scss 变量,但它不起作用。
myvar.scss文件:
$color: red;
:export {
color: $color;
}
.myclass {
background-color: $color;
}
Run Code Online (Sandbox Code Playgroud)
App.js文件:
import variables from './myvar.scss';
const App = () => {
console.log(variables);
return <div className="myclass">Hello</div>
}
export default App;
Run Code Online (Sandbox Code Playgroud)
div 背景是红色的,所以 myvar.scss 正在工作。但是variables是一个空对象。
(反应版本:17.0.1)
node_modules\react-scripts\config\webpack.config.js
module: {
strictExportPresence: true,
rules: [
{ parser: { requireEnsure: false } },
{
oneOf: [
...
{
test: sassRegex, …Run Code Online (Sandbox Code Playgroud) TABS您能告诉我为什么在 safari 浏览器中使用时焦点不会转到按钮上或没有指示焦点位于按钮上吗?
在 Chrome 中它工作正常。问题出在SAFARI浏览器上。
这是我的代码 https://codesandbox.io/s/charming-paper-k7bg3?file=/src/styles.css
.App {
font-family: sans-serif;
text-align: center;
}
/* .js-focus-visible :focus:not(.focus-visible) {
outline: 0;
} */
button:focus,
a:focus {
outline-offset: 2px;
outline-width: 2px !important;
outline-style: dotted !important;
outline-color: currentColor;
}
.App button:focus,
.App a:focus {
outline: none !important;
}
.App button:focus-visible,
.App a:focus-visible {
outline-offset: 2px;
outline-width: 2px !important;
outline-style: dotted !important;
outline-color: currentColor;
}
.js-focus-visible :focus:not(.focus-visible) {
outline: none !important;
}
/*
Optionally: Define a strong focus indicator for …Run Code Online (Sandbox Code Playgroud) javascript ×5
css ×3
reactjs ×3
icss ×2
sass ×2
angularjs ×1
col ×1
colgroup ×1
html ×1
html-table ×1
jquery ×1
node.js ×1
phantomjs ×1
router ×1
typescript ×1
visibility ×1