似乎在凤凰中配置文件的加载和编译方式在使用config.exs或中使用第三方模块时会出现问题dev.exs/prod.exs/test.exs.
示例:要设置Guardian进行JWT身份验证,我正在尝试使用该JOSE.JWK模块在我的JWK创建/加载config.exs.我可以在控制台中使用该模块iex -S mix phoenix.server.它当然是作为依赖项安装的.我得到的错误是
** (Mix.Config.LoadError) could not load config config/config.exs
** (UndefinedFunctionError) undefined function JOSE.JWK.from_file/2 (module JOSE.JWK is not available)
Run Code Online (Sandbox Code Playgroud)
这是我的config.exs中的代码
# Configure Guardian for JWT Authentication
config :guardian, Guardian,
allowed_algos: ["HS512"], # optional
verify_module: Guardian.JWT, # optional
issuer: "MyApp",
ttl: { 30, :days },
verify_issuer: true, # optional
secret_key: System.get_env("GUARDIAN_KEY_PASSPHRASE") |> JOSE.JWK.from_file(System.get_env("GUARDIAN_KEY_FILE")),
serializer: MyApp.GuardianSerializer
Run Code Online (Sandbox Code Playgroud)
当我将调用包装JOSE.JWK.from_file/2在匿名函数中时,它可以工作.但是当然Guardian.config(:secret_key)的值是匿名函数本身而不是它的返回值:
# Configure Guardian for JWT Authentication
config :guardian, …Run Code Online (Sandbox Code Playgroud) 我有点陷入如何实际设置与变更集的关联.我在我的模型中有这个代码:
defmodule MyApp.MemberApplication do
use MyApp.Web, :model
use Ecto.Schema
use Arc.Ecto.Schema
alias MyApp.Repo
alias MyApp.MemberApplication
schema "applications" do
field :name, :string
field :email, :string
field :time_accepted, Ecto.DateTime
field :time_declined, Ecto.DateTime
belongs_to :accepted_by, MyApp.Admin
belongs_to :declined_by, MyApp.Admin
timestamps()
end
def set_accepted_changeset(struct, params \\ %{}) do
struct
|> cast(params, [:time_accepted, :accepted_by_id])
|> cast_assoc(params, :accepted_by)
|> set_time_accepted
end
defp set_time_accepted(changeset) do
datetime = :calendar.universal_time() |> Ecto.DateTime.from_erl
put_change(changeset, :time_accepted, datetime)
end
end
Run Code Online (Sandbox Code Playgroud)
我想保存一个关联Admin执行某个操作(接受或拒绝member_application)和时间戳.时间戳的生成有效,但是当我尝试保存关联时,我总是得到错误
** (FunctionClauseError) no function clause matching in Ecto.Changeset.cast_assoc/3
Run Code Online (Sandbox Code Playgroud)
这就是我想要设置关联的方式: …
有人可以解释Angular 2中组件中私有属性和非私有属性之间的区别吗?像private_text和other_text在这个例子:
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'my-component',
template: '<div>{{private_text}}</div><div>{{other_text}}</div>'
})
export class MyComponent {
private private_text:string;
other_text:string;
constructor() {
this.private_text = "hello";
this.other_text = "hello";
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个表单,其中一个字段充当自动完成.如果用户输入单词并按Enter键,则该字段的内容应添加到该字段下方的列表中.
问题:当用户点击进入时,自然会提交整个表单.
我已经return false处理了处理按键的功能.但是,即使在调用此函数之前,表单似乎也已提交.
我该如何防止这种情况发生?
基本形式:
<div id="profileForm">
<form [formGroup]="profileForm" (ngSubmit)="onSubmit()" method="post" *ngIf="!showSuccessMessage">
<div class="row">
<div class="form-group col-xs-12 col-sm-6">
<label for="first_name">My Skills</label>
<div class="autocomplete">
<input formControlName="skill_string" [(ngModel)]="skillString" name="skill_string"
type="text" class="form-control" id="skill_string" placeholder="Comma separated" (keyup.enter)="skillsHandleEnter(skillString)">
<ul class="autocomplete-list" *ngIf="skillHints.length > 0">
<li class="list-item" *ngFor="let skill of skillHints" (click)="addSkillFromAutocomplete(skill)">{{skill}}</li>
</ul>
</div>
<div id="skill-cloud" class="tag-cloud">
<span class="skill-tag tag label label-success" *ngFor="let skill of selectedSkills" (click)="removeSkill(skill)">{{skill}} x</span>
</div>
</div>
</div>
<div class="row">
<hr>
<div class="form-group submit-group">
<div class="col-sm-12">
<button type="submit" class="btn btn-primary pull-right" …Run Code Online (Sandbox Code Playgroud) 如何在不使用disabled ="true"的情况下阻止用户更改输入字段中的值(包含要复制到剪贴板的特定值)?一旦用户点击该字段(已经有效),就应该选择该文本,但输入任何内容都应该没有效果.
谢谢
jQuery('input.autoselect[value]').focus(function() { jQuery(this).select(); });
Run Code Online (Sandbox Code Playgroud) 我知道如何通过AngularJS中的ng-change对textarea中的用户输入做出反应.但是如何在Angular控制器中获取当前输入?我$(this).value();在jQuery中遗漏了一些东西.
<script>
angular.module('changeExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.evaluateChange = function() {
console.log("How do I get the current content of the field?");
};
}]);
</script>
<div ng-controller="ExampleController">
<textarea ng-change="evaluateChange()" id="ng-change-example1"></textarea>
</div>
Run Code Online (Sandbox Code Playgroud) 在这个小卫生功能的Phoenix/Elixir应用程序中,当用户没有输入电子邮件时,我会遇到问题.
我正在使用结构来处理数据.一个简单的卫生功能(现在)只是剥离空白并更新结构(地图).到目前为止,它的工作很好,但是当领域email是nil,我得到一个错误.
** (FunctionClauseError) no function clause matching in String.Unicode.strip/1
Run Code Online (Sandbox Code Playgroud)
所以我引入了一个guard子句来检查这种情况,然后只清理用户名.
defmodule MyApp.User do
defstruct username: nil, email: nil, password: nil, hashed_password: nil
# Sanitizing input without guard clause
def sanitize_user(user)do
%{user | username: String.strip(user.username), email: String.strip(user.email)}
end
# Sanitizing input with guard clause
def sanitize_user(user) when is_nil(user.email) do
%{user | username: String.strip(user.username)}
end
def sanitize_user(user) when is_binary(user.email) do
%{user | username: String.strip(user.username), email: String.strip(user.email)}
end
end
Run Code Online (Sandbox Code Playgroud)
现在我在编译时遇到错误:
** (CompileError) web/models/user.ex:54: cannot invoke remote function Access.get/2 …Run Code Online (Sandbox Code Playgroud) 这可能是一个非常简单的问题,但我在Waterline文档中找不到任何相关内容.
如何在不立即保存的情况下获取Waterline模型的实例.
Model.create(data); // already written to database
Run Code Online (Sandbox Code Playgroud)
我正在寻找类似的东西
var user = User.new(data); // new instance, not persistent so far
user.doSomething(withThis); // call method on instance
user.save(); // Now write it to database
Run Code Online (Sandbox Code Playgroud)
谢谢
我有一个带有键值对的Map和一个带有原子的元组.我想删除地图中的任何条目,其中键不是元组中的原子
m = %{value1: nil, value2: nil, value4: nil}
t = {:value1, :value3, :value4}
# The result should be %{value1: nil, value4: nil}
Run Code Online (Sandbox Code Playgroud)
这是一种交叉问题.我调查了一下Enum.filter,MapSet但没有找到一个优雅的解决方案.这必须是一个常见问题,您的意见得到高度赞赏.
我对Typescript仍然很陌生,并且难以绕过接口.据我所知,接口是类的描述或类的合同.它允许我定义一个类可以具有哪些属性以及它们是哪种类型.我尝试实现它,但总是得到这个错误:
error TS2420: Class 'ResultPage' incorrectly implements interface 'ResultPageInterface'.
Property 'entries' is missing in type 'ResultPage'.
Run Code Online (Sandbox Code Playgroud)
这是界面的代码
export interface ResultPageInterface {
entries:Array<any>;
page_number:number;
page_size:number;
total_entries:number;
}
export class ResultPage implements ResultPageInterface {}
Run Code Online (Sandbox Code Playgroud)
在这里我想要使用它的类.
import { Injectable } from '@angular/core';
import { ResultPage } from '../interfaces/result-page.interface';
@Injectable()
export class SomeClass {
constructor() {}
buildPage(res:any): ResultPage {
let page:ResultPage = new ResultPage();
page.entries = res.data;
page.page_number = res.pagination.page_number;
page.page_size = res.pagination.page_size;
page.total_entries = res.pagination.total_entries;
return page;
}
}
Run Code Online (Sandbox Code Playgroud) elixir ×4
javascript ×4
angular ×3
jquery ×2
angularjs ×1
ecto ×1
node.js ×1
sails.js ×1
typescript ×1
waterline ×1