我知道ng-click如果我$event像这样传入对象,我可以访问click事件:
<button ng-click="myFunction($event)">Give me the $event</button>
<script>
function myFunction (event) {
typeof event !== "undefined" // true
}
</script>
Run Code Online (Sandbox Code Playgroud)
$event每次都必须明确传递,这有点烦人.ng-click默认情况下是否可以设置为以某种方式将其传递给函数?
javascript javascript-events angularjs angularjs-directive angularjs-ng-click
我有一个HTML5日期输入,我希望默认情况下将其值设置为我的模型中的日期属性的值.我对格式化并不是太挑剔,因为Chrome似乎根据我的语言环境决定对我来说,但理想情况下格式会一致dd/MM/yyyy.
这是我设置输入的方式:
<input type="date"
ng-model="date"
value="{{ date | date: 'yyyy-MM-dd' }}" />
Run Code Online (Sandbox Code Playgroud)
这在Chrome上工作正常,默认情况下我会看到以下内容:

(我仍然不太明白为什么必须提供值yyyy-MM-dd,如果Chrome仍然根据我的语言环境对其进行格式化,但这是一个不同的问题.)
我的问题是Firefox没有以我指定的方式显示日期的值.我认为这与将输入绑定到date模型有关,因为我可以在value属性中指定几乎任何字符串,并且我仍然会在输入中看到默认的长日期字符串:

如果我ng-model="date"从输入标签中删除,Firefox会很好地显示我给它的任何值.我不认为输入绑定的模型实际上对其默认值有任何影响?
我理解普遍不支持日期输入,但看到它应该依赖于简单的文本输入,我不明白为什么它的值不会简单地2013-08-05由angular的日期过滤器指定.
那么,如何让Firefox在日期输入中接受我的格式化值?
注意在用户完成编辑后,我当然会执行验证并将每个日期输入值转换为适当的Date对象.不确定这是否与问题相关,而是将其放在那里以防万一,因为输入格式显然需要保持一致,以便日期转换在所有浏览器中都能正常工作.当然有问题,Chrome决定我的输入格式......
jsfiddle http://jsfiddle.net/KfSBq/
通过子对象我的意思是我用ng-repeat显示的对象都包含一个对象列表,我希望根据其中一个子对象的属性进行过滤.
仅这一点就很容易了.我有一个对象dailies,每个对象包含一个date和一个entries对象列表:
function Ctrl($scope) {
$scope.dailies = [{date: new Date('07/07/2013'),
entries: [{category: 'A', note:'Lorem ipsum'},
{category: 'B', note: 'Lorem ipsum'}]},
{date: new Date('05/02/2013'),
entries: [{category: 'A', note: 'Lorem ipsum'}]}];
}
Run Code Online (Sandbox Code Playgroud)
我显示它们,按类别过滤:
<div ng-controller="Ctrl">
<div class="daily" ng-repeat="daily in dailies | orderBy:'-date' ">
{{ daily.date | date:'dd/MM/y' }}
<div class="entry" ng-repeat="entry in daily.entries | filter:{ category: 'B'} ">
<span>{{ entry.category }}</span>, <span>{{ entry.note }}</span>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我的问题是,现在仍然不显示任何条目的日常对象.我如何实现这样一种情况:如果过滤使得entries列表为daily空,daily则不会显示?
在Sublime Text中,您可以使用Ctrl +单击将光标添加到多个任意位置.但是,使用鼠标通常是不精确的,所以我有时会遇到撤消点击的需要(已经在文本中选择了多个位置),但是还没有找到办法,所以我必须从头开始.
有没有办法在使用鼠标指定光标后"删除"?
注意:我知道键盘有多个光标使用,这个问题具体是关于鼠标的使用.
我试图从使用python的包含给定子字符串的字符串中获取句子.
我可以访问字符串(学术摘要)和包含开始和结束索引的突出显示列表.例如:
{
abstract: "...long abstract here..."
highlights: [
{
concept: 'a word',
start: 1,
end: 10
}
{
concept: 'cancer',
start: 123,
end: 135
}
]
}
Run Code Online (Sandbox Code Playgroud)
我循环遍历每个突出显示,在摘要中找到它的起始索引(结尾并不重要,因为我只需要在句子中获取位置),然后以某种方式需要识别索引出现的句子.
我能够使用抽象将抽象标记为句子nltk.tonenize.sent_tokenize,但通过这样做,我使索引位置无用.
我该如何解决这个问题?我认为正则表达式是一个选项,但是nltk标记化器似乎是一种很好的方式来做它,如果不使用它将是一种耻辱.或者以某种方式重置起始索引,通过查找自上一次完全停止后的字符数/感叹号/问号?
这是一个工作示例,说明我如何设置一个拦截器,为每个请求附加一个身份验证令牌(这或多或少来自https://docs.angularjs.org/api/ng/service/ $ http)
angular.module("app", [])
.config(function ($httpProvider) {
$httpProvider.interceptors.push("authInterceptor");
})
.factory("authInterceptor", function ($q) {
return {
// interceptor configuration here
}
})
Run Code Online (Sandbox Code Playgroud)
我config和我的run块中有很多其他的东西,它们调用和启动来自不同角度模块的服务,所以我想稍微整理一下.但是我知道在config块中依赖注入有一些非常具体的规则,我不太明白,这些都阻止我authInterceptor在一个单独的模块中定义我的工厂.由于config和run块中的其他逻辑调用应用程序中的其他模块,因此声明拦截器在那里看起来不合适.
这就是我想要做的:
angular.module("services.authInterceptor", [])
.factory("authInterceptor", function ($q) {
return {
// interceptor configuration here
}
});
angular.module("app", [
"services.authInterceptor"
]).config(function ($httpProvider, authInterceptor) {
$httpProvider.interceptors.push("authInterceptor");
});
// Error: Unknown provider authInterceptor.
Run Code Online (Sandbox Code Playgroud)
我尝试将它注入到run块中,但我想你不允许注入$httpProvider它:
angular.module("app", [
"services.authInterceptor"
]).run(function ($httpProvider, authInterceptor) {
$httpProvider.interceptors.push("authInterceptor");
});
// …Run Code Online (Sandbox Code Playgroud) javascript dependency-injection angularjs angularjs-module angular-http-interceptors
我正在构建一个仅使用本机、普通 JS 功能(ES6、Web 组件、导入模块)的网站。
我想包含一个 polyfill 来让 Safari 支持扩展 HTML 元素 ( class MyLink extends HTMLAnchorElement)。理想情况下,我想通过importmain.js 文件中包含它,而不是作为<script>index.html 中的标签。
我首先尝试了官方的Custom Elements V1 polyfill,包括通过脚本标签 ( <script src="https://unpkg.com/@webcomponents/custom-elements"></script>) 和import(import "https://cdn.skypack.dev/@webcomponents/custom-elements"; )。两种方式都没有错误,但我没有看到在 Safari 上扩展内置元素的支持。
我尝试了一个不同的polyfill,它明确提到了可定制的内置元素,在这种情况下,通过脚本标签添加它确实可以在Safari上运行:
<script src="//unpkg.com/@ungap/custom-elements"></script>
Run Code Online (Sandbox Code Playgroud)
但如果我在我的js中导入它仍然不起作用:
import ungapCustomElements from "https://cdn.skypack.dev/@ungap/custom-elements";
Run Code Online (Sandbox Code Playgroud)
我是否使用了错误的 CDN?错误的填充材料?有什么不同?为什么它可以通过脚本标签工作,但不能作为 ES6 导入?
如果相关的话,这是我尝试使用的自定义元素的声明:
class ButtonLink extends HTMLAnchorElement {
connectedCallback() {
console.log("This is not called on Safari");
}
}
customElements.define("button-link", ButtonLink, { extends: "a" });
Run Code Online (Sandbox Code Playgroud) 出于某种原因,我无法使用jQuery通过id检索隐藏的输入.
我可以
> $('input')
[<input type=?"checkbox" name=?"property-type" id checked>?, <input type=?"checkbox" name=?"property-type" id checked>?, <input type=?"checkbox" name=?"property-type" id>?, <input type=?"checkbox" name=?"property-type" id>?, <input type=?"hidden" name=?"no-of-rooms" id=?"1-rooms">?, <input type=?"hidden" name=?"no-of-rooms" id=?"2-rooms" checked>?, <input type=?"hidden" name=?"no-of-rooms" id=?"3-rooms" checked>?, <input type=?"hidden" name=?"no-of-rooms" id=?"4-rooms">?, <input type=?"hidden" name=?"no-of-rooms" id=?"5-rooms">?, <input type=?"hidden" name=?"no-of-rooms" id=?"over-5-rooms">?, <input type=?"checkbox" name=?"property-type" id>?, <input type=?"checkbox" name=?"property-type" id>?, <input type=?"checkbox" name=?"property-type" id>?]
Run Code Online (Sandbox Code Playgroud)
它可以很好地获取页面上的所有输入,包括type = hidden.
我也可以
> $('input[type="hidden"]')
[<input type=?"hidden" name=?"no-of-rooms" id=?"1-rooms">?, <input type=?"hidden" name=?"no-of-rooms" id=?"2-rooms" checked>?, <input type=?"hidden" name=?"no-of-rooms" id=?"3-rooms" checked>?, …Run Code Online (Sandbox Code Playgroud) 我在尝试设置一个内部没有文本的按钮时,遇到了一个有趣的HTML按钮标记行为,只有一个字体图标 - 没有文本的按钮会导致所有后续按钮都按下文本.仅当按钮具有height指定的属性时才会出现此问题.
<header>
<button><!-- No text here --></button>
<button>This button is pushed down</button>
</header>
button { height: 40px; }
Run Code Online (Sandbox Code Playgroud)
起初我确信这是由于第一个按钮内部的字体图标做了一些奇怪的基线魔术,但正如你从最小的工作示例中看到的那样,当按钮内部根本没有内容时,行为就会得到维护.
我可以通过向第一个按钮添加内容来解决这个问题,但由于我的唯一内容是a <span class="icon user"></span>,这是一个字体图标,它实际上会干扰字体基线,并将按钮放在几个像素上.这就是为什么我决定将图标置于绝对位置,这解决了原来的轻微定位问题,但引入了这个新的,因为按钮现在就像是空的一样.
所以,问题仍然存在 - 如何避免使用空按钮定位问题?
注意:似乎以上只发生在webkit浏览器上; Firefox正确地定位了带有文本的按钮,但是将空的按钮向上推.
我知道有关重定向特定路由的信息:
put 'users/:user_id', to: redirect('/api/v1/users/:user_id')
Run Code Online (Sandbox Code Playgroud)
如何将重定向应用于由生成的所有路由resources?寻找类似的东西
resources :users, to: redirect('/api/v1')
Run Code Online (Sandbox Code Playgroud)
我可以使用match实现一种解决方法,但这有点笨拙:
match 'users/*path', to: redirect('/api/v1/users/%{path}'), via: [:GET, :POST, :PUT, :DELETE]
Run Code Online (Sandbox Code Playgroud) angularjs ×4
javascript ×4
forms ×2
cdn ×1
css ×1
date ×1
es6-modules ×1
hidden-field ×1
html ×1
html5 ×1
htmlbutton ×1
input ×1
jquery ×1
nltk ×1
position ×1
python ×1
redirect ×1
regex ×1
sublimetext2 ×1