- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在编写我的第一个 Electron/Angular/RequireJS 单页桌面应用程序。我从 electron-boilerplate 开始而且效果很好。然而,我需要将 AngularJs 添加到等式中——样板已经使用了 RequireJS。我尝试了多种解决方案,但要么出现错误,要么依赖项未执行。因此,我尝试实现之前堆栈溢出问题“Simple requireJS with angularJS - angular is not defined”中的简单示例。然而,我看到的是文件正在被解析,但它从不执行里面的代码。这几乎就像一个或多个依赖项未得到满足,因此它们不会执行。我的文件如下 - 我添加了一些日志记录,以便我可以轻松查看执行路径。
app.html -- 包含 RequireJS 的起点。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Electron Boilerplate</title>
</head>
<body ng-app="ReqApp" ng-controller="GreetCtrl">
<h1>{{greeting}}!</h1>
<script data-main="require_config" src="vendor/require.js"></script>
</body>
</html>
require_config.js -- 这包含 RequireJS 配置。
console.log("REQUIRE_CONFIG.JS-------------"+requirejs.version);
requirejs.config({
// alias libraries paths
paths: {
'domReady': './vendor/requirejs-domready',
'angular': './node_modules/angular/angular',
'GreetCtrl': './js/GreetCtrl',
'app': './js/app'
},
// angular does not support AMD out of the box, put it in a shim
shim: { 'angular': { exports: 'angular' }
},
// kick start application
deps: ['./bootstrap']
});
bootstrap.js——来自 RequireJS 的文件 deps
手动引导 AngularJS。
console.log("BOOTSTRAP.JS1-------------");
define([
'require',
'angular',
'app'
], function (require, ng, app) {
'use strict';
console.log("BOOTSTRAP.JS2+++++++++++++");
require(['domReady!'], function (document) {
console.log("BOOTSTRAP.JS+++++++++++++");
ng.bootstrap(document, ['ReqApp']);
});
});
./js/app.js -- 这会初始化应用程序的 AngularJS 模块。
console.log("APP.JS-------------"+requirejs.version);
define([
'angular',
'GreetCtrl'
], function (ng) {
'use strict';
console.log("APP.JS+++++++++++++");
return ng.module('ReqApp', [ 'ReqApp.GreetCtrl' ]);
});
./js/GreetCtrl.js
console.log("GREETCTRL.JS1-------------");
define(['angular'], function(angular) {
console.log("GREETCTRL.JS1+++++++++++++");
angular.module( 'ReqApp.GreetCtrl', [])
.controller( 'GreetCtrl', function GreetCtrl ($scope) {
$scope.greeting = "Hello World";
});
});
运行此示例的控制台输出为:
[16982:0917/115914:ERROR:browser_main_loop.cc(173)] Running without the SUID sandbox! See https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment for more information on developing with the sandbox on.
[17010:0917/115915:INFO:renderer_main.cc(200)] Renderer process started
[17014:0917/115915:INFO:renderer_main.cc(200)] Renderer process started
[16982:0917/115915:ERROR:browser_gpu_channel_host_factory.cc(146)] Failed to create channel.
[16982:0917/115915:INFO:CONSOLE(43)] "REQUIRE_CONFIG.JS-------------2.1.20", source: file:///home/swdev/projects/build/require_config.js (43)
[16982:0917/115915:INFO:CONSOLE(8)] "BOOTSTRAP.JS1-------------", source: file:///home/swdev/projects/build/bootstrap.js (8)
页面输出为:
{{greeting}}!
从输出中可以看到,似乎只解析了 require_config.js 和 bootstrap.js 文件,但定义中的代码并未执行。我的问题是:
requirejs
,我需要删除对 require
的使用吗?来自 bootstrap.js 并将其替换为 requirejs
还有?注意:我已经测试过更改此设置,但它对我的问题没有任何帮助。ng-app="ReqApp"
在 HTML 正文定义中。我有限的理解是,这应该被删除,因为我们正在手动引导 AngularJS。我的用例(Election(node)/RequireJS/AngularJS)的正确方法是什么?注意:我已经通过从主体定义中删除定义进行了测试,但它对我的问题没有任何作用。我花了几天时间尝试解决这个问题,因此我们将非常感谢任何帮助!
<小时/>其他尝试:多玩一些来简化部分问题。我似乎无法让 RequireJS 执行或解析某些依赖项。我的简化是:
./app.js
<!doctype html>
<html>
<head>
<title>Electron Boilerplate</title>
</head>
<body >
<script data-main="require_config" src="vendor/require.js"></script>
<h1>Hello World!</h1>
</body>
</html>
./require_config.js
console.log("REQUIRE_CONFIG.JS-------------"+requirejs.version);
requirejs.config({
paths: {
'app': './js/app'
},
// kick start application
deps: ['./bootstrap']
});
./bootstrap.js
console.log("BOOTSTRAP.JS1-------------");
define( ['app'], function (app) {
'use strict';
console.log("BOOTSTRAP.JS2+++++++++++++");
});
./js/app.js
console.log("APP.JS-------------");
define([], function () {
'use strict';
console.log("APP.JS+++++++++++++");
});
结果输出仍然与我上面的原始输出相同。 boostrap.js 和 require_config.js 已处理。 bootstrap.js 定义/函数永远不会被调用,app.js 永远不会被解析。
最佳答案
contacting之后Electron boilerplate 的开发者我想他让我改正了。主要问题是我对样板的所有移动部分缺乏了解。当尝试扩展样板文件时,我当时没有意识到/理解他的应用程序是使用 ES6 编写的,ES6 已被转换为兼容的 RequireJS 格式。因此我遇到的问题根本不是 RequireJS 的问题。我编写的模块符合 RequireJS,然后被转译,这意味着 RequireJS 无法处理它们。
正确的方法是编写 ES6 模块,问题就消失了。一种解决方法是使用符合 RequieJS 的语法添加模块,然后修改样板 build.js copyFromAppDir
以排除这些文件被转译。但同样,为了遵循样板的初衷和设计,代码应该使用 ES6 编写。
关于javascript - 简单的 RequireJS、AngularJS、Electron App、依赖项未执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32630588/
我正在努力实现以下目标, 假设我有字符串: ( z ) ( A ( z ) ( A ( z ) ( A ( z ) ( A ( z ) ( A ) ) ) ) ) 我想编写一个正则
给定: 1 2 3 4 5 6
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
大家好,我卡颂。 Svelte问世很久了,一直想写一篇好懂的原理分析文章,拖了这么久终于写了。 本文会围绕一张流程图和两个Demo讲解,正确的食用方式是用电脑打开本文,跟着流程图、Demo一
身份证为15位或者18位,15位的全为数字,18位的前17位为数字,最后一位为数字或者大写字母”X“。 与之匹配的正则表达式: ?
我们先来最简单的,网页的登录窗口; 不过开始之前,大家先下载jquery的插件 本人习惯用了vs2008来做网页了,先添加一个空白页 这是最简单的的做法。。。先在body里面插入 <
1、MySQL自带的压力测试工具 Mysqlslap mysqlslap是mysql自带的基准测试工具,该工具查询数据,语法简单,灵活容易使用.该工具可以模拟多个客户端同时并发的向服务器发出
前言 今天大姚给大家分享一款.NET开源(MIT License)、免费、简单、实用的数据库文档(字典)生成工具,该工具支持CHM、Word、Excel、PDF、Html、XML、Markdown等
Go语言语法类似于C语言,因此熟悉C语言及其派生语言( C++、 C#、Objective-C 等)的人都会迅速熟悉这门语言。 C语言的有些语法会让代码可读性降低甚至发生歧义。Go语言在C语言的
我正在使用快速将 mkv 转换为 mp4 ffmpeg 命令 ffmpeg -i test.mkv -vcodec copy -acodec copy new.mp4 但不适用于任何 mkv 文件,当
我想计算我的工作簿中的工作表数量,然后从总数中减去特定的工作表。我错过了什么?这给了我一个对象错误: wsCount = ThisWorkbook.Sheets.Count - ThisWorkboo
我有一个 perl 文件,用于查看文件夹中是否存在 ini。如果是,它会从中读取,如果不是,它会根据我为它制作的模板创建一个。 我在 ini 部分使用 Config::Simple。 我的问题是,如果
尝试让一个 ViewController 通过标准 Cocoa 通知与另一个 ViewController 进行通信。 编写了一个简单的测试用例。在我最初的 VC 中,我将以下内容添加到 viewDi
我正在绘制高程剖面图,显示沿路径的高程增益/损失,类似于下面的: Sample Elevation Profile with hand-placed labels http://img38.image
嗨,所以我需要做的是最终让 regStart 和 regPage 根据点击事件交替可见性,我不太担心编写 JavaScript 函数,但我根本无法让我的 regPage 首先隐藏。这是我的代码。请简单
我有一个非常简单的程序来测量一个函数花费了多少时间。 #include #include #include struct Foo { void addSample(uint64_t s)
我需要为 JavaScript 制作简单的 C# BitConverter。我做了一个简单的BitConverter class BitConverter{ constructor(){} GetBy
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我是 Simple.Data 的新手。但我很难找到如何进行“分组依据”。 我想要的是非常基本的。 表格看起来像: +________+ | cards | +________+ | id |
我现在正在开发一个 JS UDF,它看起来遵循编码。 通常情况下,由于循环计数为 2,Alert Msg 会出现两次。我想要的是即使循环计数为 3,Alert Msg 也只会出现一次。任何想法都
我是一名优秀的程序员,十分优秀!