我对构建应用程序的方式感到好奇(我可能在无关紧要的事情上浪费了时间),但好奇心仍然让我发问。
在 AngularJS 中,应用程序如何工作?例如,如果我在 app.js 中有此代码(删除了我的实现,仅显示结构):
(function() {
'use strict';
angular
.module('app', ['ui.router', 'satellizer', 'permission', 'angular-jwt', 'ui.bootstrap', 'angular-loading-bar'])
.config(['$stateProvider', '$urlRouterProvider', '$authProvider', '$locationProvider', '$httpProvider', Config])
.run(['$rootScope', '$state', '$auth', 'jwtHelper', 'Permission', Run]);
function Run($rootScope, $state, $auth, jwtHelper, userService, Permission) {
// Some code
}
function Config($stateProvider, $urlRouterProvider, $authProvider, $locationProvider, $httpProvider) {
// Some code
}
})();
Run Code Online (Sandbox Code Playgroud)
..什么先运行?我很好奇,因为我想知道我是否应该放在run之前config,等等。我不想加载配置,而是等待run做某事,而run先加载会更有效率,所以无需等待......如果这甚至是一个问题的话。
任何澄清将不胜感激。
我对我的 CSP 标头遵循Google 的严格 CSP 政策,并且我正在正确添加随机数,但是我的脚本在浏览器中不断收到此错误:
拒绝加载脚本 ' http://localhost:8080/client/dist/inline.6e0c61259742e86be1dd.bundle.js ' 因为它违反了以下内容安全策略指令:“script-src nonce-XVlBzgbaiCMRAjWwhTHctcuAxhxKQFDaFxhxKQFDaFpLSEFWJFunc' -eval' '严格动态' https: http:"。存在“strict-dynamic”,因此禁用了基于主机的白名单。
如您所见,随机数与脚本中的随机数匹配:
<script type="text/javascript" src="/client/dist/inline.6e0c61259742e86be1dd.bundle.js" nonce="XVlBzgbaiCMRAjWwhTHctcuAxhxKQFDaFpLSjFbcXoEFfRsWxP"></script>
Run Code Online (Sandbox Code Playgroud)
这是我用于script-src. "%s" 表示随机生成的随机数,它将在响应设置标头之前进行插值:
script-src nonce-%s 'unsafe-inline' 'unsafe-eval' 'strict-dynamic' https: http:;
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么?
比如说,你有这个HTML代码:
<ul>
<li class="hello">Hello</li>
</ul>
<h1 class="hello">Hello<h1>
Run Code Online (Sandbox Code Playgroud)
如果我通过以下jQuery伴随它,那么.hello类文本将更改为"hello",而不是"Hello":
$(document).ready(function() {
$(".hello").text("hello");
});
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果我只想在li中定位.hello类,那么我能够将上面的代码重建为这样的代码吗?:
$(document).ready(function() {
$("li .hello").text("hello");
});
Run Code Online (Sandbox Code Playgroud)
此外,如果那个DOES工作,允许的项目限制是什么,或者它与CSS类似,你可以根据需要嵌套任意数量的项目,例如body header .li:nth-child(1)?
请记住,我第一次学习jQuery同时提出这个问题而且目前没有编辑器来测试它.
我正在努力学习Haskell,这是我在函数式编程中的第一种方法.我在创建一个以数字作为输入并逐个打印该数字的函数时遇到了一些麻烦,直到0.
printDescending n = if n > 0
then printDescending n - 1 return n
else return n - 1
Run Code Online (Sandbox Code Playgroud)
我希望能够做到printDescending 20并输出20,19,18 ...... 2,1,0.但是我收到了这个错误:
> • Non type-variable argument
> in the constraint: Num ((a -> m a) -> a1 -> m1 a1)
> (Use FlexibleContexts to permit this)
> • When checking the inferred type
> printDescending :: forall (m :: * -> *) a (m1 :: * -> *) a1.
> (Ord a1, Num ((a -> …Run Code Online (Sandbox Code Playgroud) 我想创建一个指令,我可以使用模板变量,这样我就可以访问全局变量,类似于$rootScopeAngular.JS,而不必在我需要变量的每个组件中注入服务.
例如:
@Directive({
selector: '[app]',
exportAs: 'app'
})
export class AppDirective {
isLoggedIn: boolean = false;
constructor() {
// Do some stuff to set 'this.ready'...
}
}
Run Code Online (Sandbox Code Playgroud)
我希望能够在我的模板中使用上面的代码,如下所示:
<div #app>
<div *ngIf="app.isLoggedIn">...</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这样的事情可能吗?
如果我有这样的包范围变量:
var (
bus *Bus // THIS VARIABLE
)
// Bus represents a repository bus. This contains all of the repositories.
type Bus struct {
UserRepository *UserRepository
// ...
}
Run Code Online (Sandbox Code Playgroud)
...我可以访问bus我的存储库中的变量,以便它们可以相互访问,如果它们可以同时使用,我是否需要使用任何类型的互斥?
会发生什么的快速伪代码:
// Router
router.GET("/user/:id", c.FindUser)
// Controller
func (c *UserController) FindUser(w http.ResponesWriter, r *http.Request) {
w.Write([]byte(c.UserService.FindUser(r.Get("id"))))
}
// Service
func (s UserService) FindUser(id int) *domain.User {
return s.UserRepository.FindByID(id)
}
// Repository
func (r UserRepository) FindByID(id int) *domain.User {
// This is where the package-scope `bus` variable will …Run Code Online (Sandbox Code Playgroud) javascript ×2
angular ×1
angularjs ×1
browser ×1
go ×1
haskell ×1
http ×1
http-headers ×1
jquery ×1
recursion ×1
security ×1
typescript ×1