我正在使用Andrew McGivery的 AngularJS肥皂服务
从Chrome调用它时效果很好,但它在Firefox和IE11上返回了一个typeError.
TypeError:在angular.soap.js第16行,e为null
有问题的代码如下:
.factory("$soap",['$q',function($q){
return {
post: function(url, action, params){
var deferred = $q.defer();
//Create SOAPClientParameters
var soapParams = new SOAPClientParameters();
for(var param in params){
soapParams.add(param, params[param]);
}
var soapCallback = function(e){
//ERROR THROWN ON LINE BELOW
if(e.constructor.toString().indexOf("function Error()") != -1){
deferred.reject("An error has occurred.");
} else {
deferred.resolve(e);
}
}
SOAPClient.invoke(url, action, soapParams, true, soapCallback);
return deferred.promise;
},
setCredentials: function(username, password){
SOAPClient.username = username;
SOAPClient.password = password;
}
}
}]);
Run Code Online (Sandbox Code Playgroud)
Chrome中的e是我的webservice(用户对象)返回的对象,在Firefox中它是null,我不知道在库中查找调试问题的位置.
更新:
我的控制器看起来像这样: …
在Chrome(版本45.0.2454.101 m)中,如果我将一个类添加到列表元素以更改其颜色,则仅在重新绘制窗口(调整大小)时更新项目符号点颜色
$("#a").click(function() {
$("#a").addClass('blue');
});Run Code Online (Sandbox Code Playgroud)
ul li {
color: red;
list-style-type: disc;
margin-left: 2em;
}
.blue {
color: blue;
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<ul>
<li id="a">a</li>
<li id="b">b</li>
<li id="c">c</li>
</ul>Run Code Online (Sandbox Code Playgroud)
Chrome中的错误是否可以通过代码解决?(或者它是一个bug?)
我得到ERROR TypeError:_co.onClick不是角度为2的函数错误.
<span
class="glyphicon"
[class.glyphicon-star]="isFavorite"
[class.glyphicon-star-empty]="!isFavorite"
(click)="onClick()">
</span>
Run Code Online (Sandbox Code Playgroud)
当用户点击它应该是彩色或空的星.然后我的组件ts文件在这里
@Component({
selector: 'favorite',
templateUrl: './favorite.component.html',
styleUrls: ['./favorite.component.css']
})
Run Code Online (Sandbox Code Playgroud) 我有一个基于 ldap 的身份验证,如果用户凭据匹配,则接收承载令牌和 userId 作为 JSON 格式的响应。现在我需要将这些值保存在 cookie 中。我正在使用 angular 4。我找不到任何与 angular 4 相关的 cookie 示例。
我正在 Node.js 中开发一个应用程序,我在其中调用了一个异步函数两次,并将值分配给一个全局变量。
问题是我想使用两次调用的结果来做其他事情,但其他事情不会等待分配结果。
这是我的代码:
var a;
var b;
let x = 'abcd';
foo(x).then(data=>{
a = data;
});
x = 'efgh';
foo(x).then(data=>{
b = data;
});
console.log(a + b); // for example
Run Code Online (Sandbox Code Playgroud)
在执行之前如何等待这两个函数完成a + b?
我正在我的应用程序中实现这个按钮。
在我的按钮组件中,我有:
@Input() callback: () => Promise<null>;
onClick() {
this.spinnerService.show();
this.callback().then(() => {
this.spinnerService.hide();
}, () => {
this.spinnerService.hide();
});
}
Run Code Online (Sandbox Code Playgroud)
(我不使用 async / await 因为“技术负责人”也不想要我)
组件模板:
<my-button [callback]="doSomething">
</my-button>
Run Code Online (Sandbox Code Playgroud)
当我将这种代码传递给组件的输入时,一切正常:
doSomething = () => {
return myService.doSomething()
.toPromise()
.then((response) => console.log('promise resolved'));
}
Run Code Online (Sandbox Code Playgroud)
但我需要更早地打破这个功能:
doSomething() {
if (condition) {
return;
}
return myService.doSomething()
.toPromise()
.then((response) => console.log('promise resolved'));
}
Run Code Online (Sandbox Code Playgroud)
我得到
错误类型错误:无法读取未定义的属性“then”
我试过用相同的结果强制承诺
if (condition) {
return Promise.resolve(null);
// or
return new Promise((resolve) => { resolve(null); });
}
Run Code Online (Sandbox Code Playgroud) 我有一个PhoneNumbersFormComponent其模板如下所示:
<div [formGroup]="form">
<div formArrayName="numbers">
<input formControlName="countryPrefix">
<input formControlName="number">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想通过 angular-cli 创建的默认测试ng g component xxx
我得到的第一个错误是:
找不到名称为“countryPrefix”的控件
我用以下方法解决了这个问题:
beforeEach(() => {
fixture = TestBed.createComponent(PhoneNumbersFormComponent);
component = fixture.componentInstance;
component.phoneNumbers = [];
component.form = new FormGroup({
countryPrefix: new FormControl(),
number: new FormControl()
});
fixture.detectChanges();
});
Run Code Online (Sandbox Code Playgroud)
现在剩下的最后一个错误是:
找不到名称为“numbers”的控件
我不知道如何测试formArrayName="numbers"
我已经将save-prefix配置为默认添加'^'作为版本前缀。这对于我从npmjs安装的(无作用域和作用域)软件包非常有效。但是,对于来自我自己的注册表(verdaccio)的软件包,它不会附加前缀:
> npm install --save @my-scope/my-package
> cat package.json
...
"dependencies": {
"@my-scope/my-package": "0.0.42",
}
Run Code Online (Sandbox Code Playgroud)
从这个问题中我了解到,保存前缀是本地的,不受注册表或package.json的影响。
我是否必须在本地为注册表配置保存前缀?如果是这样:如何/在哪里?
关于为什么我自己的注册表中的软件包不使用'^'的其他想法?
我的.npmrc看起来像这样:
@oblamatik:registry=https://npm.dev.***********.ch
//npm.dev.oblamatik.ch/:_password="***************"
//npm.dev.oblamatik.ch/:username=ci
//npm.dev.oblamatik.ch/:email=ci@***********.ch
//npm.dev.oblamatik.ch/:always-auth=true
Run Code Online (Sandbox Code Playgroud) 我尝试在茉莉花测试中模拟数据。
在我使用的组件规范中:
describe('MyComponent', () => {
const user: User = require('../../mocks/user.json');
Run Code Online (Sandbox Code Playgroud)
我把一个服务存根放在/src/mocks/services/service.stub.ts
import { Observable, of } from 'rxjs';
export const MyServiceStub = {
users: require('../../mocks/users.json'),
getUsers(): Observable<any> {
return of(this.users);
}
};
Run Code Online (Sandbox Code Playgroud)
有了这个npm run 测试,但应用程序无法编译,因为
src/app/mocks/services/UserServiceStub.ts(4,15) 中的错误:错误 TS2304:找不到名称“需要”。
我试着修改tsconfig.json与
"compilerOptions": {
"resolveJsonModule": true,
"esModuleInterop": true
}
Run Code Online (Sandbox Code Playgroud)
并使用以下命令导入模拟 json:
import * as users from '../../mocks/users.json';
Run Code Online (Sandbox Code Playgroud)
这破坏了我所有的导入,如 momentJS (import * as moment from 'moment')
我读到我可以添加
"allowSyntheticDefaultImports": true
Run Code Online (Sandbox Code Playgroud)
但这并没有帮助...
在我的测试中导入 json 文件的正确方法是什么?
编辑:我忘了说require在我的规范文件中工作,当我在/src/mocks/services/MyService.stub.ts 中 …
我有一个垂直长的 SVG 图像,我需要滚动到具有特定 id 的某个特定元素。
const el = document.getElementById(id);
el.scrollIntoView({
behavior: 'smooth',
block: 'center'
});
Run Code Online (Sandbox Code Playgroud)
这在 Chrome 中效果很好,但 Firefox 会滚动到 SVG 文件的顶部,而不是所选元素的视图中。
我在 stackblitz 中重现了该错误:
https://stackblitz.com/edit/react-wkoiwq
https://react-wkoiwq.stackblitz.io
在 Chrome 中,#hotplate 元素移动到中心,而在 Firefox 中,SVG 的顶部移动到中心。
尝试更改center, 和start来end查看效果。
有没有办法解决/避免这个问题?
angular ×5
javascript ×3
typescript ×2
unit-testing ×2
angular-cli ×1
angularjs ×1
cookies ×1
css ×1
firefox ×1
jasmine ×1
jquery ×1
node.js ×1
npm ×1
promise ×1
soap ×1
verdaccio ×1