我是角度新手并拥有以下代码.
angular.module('MyApp')
.controller('loginController', ['$scope', '$http', 'conditionalDependency',
function ($scope, $http, conditionalDependency{
}
Run Code Online (Sandbox Code Playgroud)
我想有条件地加载conditionalDependency.像这样的东西
if(true)
{
//add conditionalDependency
}
Run Code Online (Sandbox Code Playgroud)
如何才能做到这一点.我看过这篇文章 .但是,我的要求是我在函数中指定了依赖项
提前致谢.
我想将 UTC 日期时间格式化为“dd/MM/yyyy hh:mm:ss a”。我使用 datepipe 尝试了这个。但是它会将其转换为本地时间。如何将 UTC 格式化为所需的格式。
Stackblitz 链接:https ://stackblitz.com/edit/angular-oxr43w
提前致谢。
我想知道是否有标准代码可以使用密钥生成 SHA256 哈希值。我遇到过几种类型的代码,但是它们不会生成相同的输出。
在JokeCamp找到的代码
private string CreateToken(string message, string secret)
{
secret = secret ?? "";
var encoding = new System.Text.ASCIIEncoding();
byte[] keyByte = encoding.GetBytes(secret);
byte[] messageBytes = encoding.GetBytes(message);
using (var hmacsha256 = new HMACSHA256(keyByte))
{
byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);
return Convert.ToBase64String(hashmessage);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我找到的另一张
private static string ComputeHash(string apiKey, string message)
{
var key = Encoding.UTF8.GetBytes(apiKey);
string hashString;
using (var hmac = new HMACSHA256(key))
{
var hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(message));
hashString = Convert.ToBase64String(hash);
}
return hashString;
}
Run Code Online (Sandbox Code Playgroud)
这两个生成的代码与http://www.freeformatter.com/hmac-generator.html#ad-output生成的代码不同 …
我有一个简单的角度(1.2.24)应用程序,我在Jasmine我的单元测试,我使用Karma和webpack.
当我执行业力时,我在单元测试中遇到了这行代码的问题
beforeEach(module('Test'));
Run Code Online (Sandbox Code Playgroud)
我得到的错误是
TypeError: module is not a function
at Suite.<anonymous> (tests.webpack.js:77:14)
at Object.<anonymous> (tests.webpack.js:75:48)
at Object.<anonymous> (tests.webpack.js:94:31)
at __webpack_require__ (tests.webpack.js:20:30)
at webpackContext (tests.webpack.js:58:10)
at Array.forEach (native)
at Object.<anonymous> (tests.webpack.js:48:17)
Run Code Online (Sandbox Code Playgroud)
这是我的karma.config.js
var webpack = require('webpack');
module.exports = function (config) {
config.set({
browsers: [ 'Chrome' ], //run in Chrome
plugins: [
'karma-jasmine',
'karma-webpack',
'karma-chrome-launcher'
],
singleRun: true, //just run once by default
frameworks: [ 'jasmine' ], //use the mocha test framework
files: [
'tests.webpack.js', //just load this file
'TestBuild/Scripts/angular.js', …Run Code Online (Sandbox Code Playgroud)