.factory('Api', function($http) {
var API = "http://127.0.0.1:4567/";
return {
get: function(method) {
return $http.get(API + method).success(function(result) {
return result;
});
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后
console.log(Api.get("MAppData"));
Run Code Online (Sandbox Code Playgroud)
返回
Object {then: function, success: function, error: function}
Run Code Online (Sandbox Code Playgroud)
为什么不返回结果(响应数据)?
我今天早些时候在stackoverflow上问了一个相关的问题,但是由于代码的复杂性(无法发布)和我自己的新手,我无法从给出的答案中真正实现解决方案.
所以现在我的问题是,对于如下代码:
$http.get(ArbitraryInput).then(function (response) {$scope.data = response});
Run Code Online (Sandbox Code Playgroud)
(您可以用上面的"成功"代替"then",我使用"then"因为根据更新的$ http api弃用了成功)
如何在$ scope.data中实际保存响应对象?从我到目前为止所做的,$scope.data当我后来输入代码时是"未定义的":
console.log($scope.data3);
Run Code Online (Sandbox Code Playgroud)
谢谢!
更新一个
显然,如果我把console.log($scope.data); 里面的控制台将显示我想要的$scope.data.但如果它在外面,它将在控制台中保持"未定义".换一种说法:
$http.get(ArbitraryInput).then(function (response) {$scope.data = response; console.log($scope.data);});
Run Code Online (Sandbox Code Playgroud)
将返回任何类型的对象响应.在控制台中,但是
$http.get(ArbitraryInput).then(function (response) {$scope.data = response;});
console.log($scope.data);
Run Code Online (Sandbox Code Playgroud)
将在控制台中返回"undefined".
我正在创建一个测验,每次我开始测验时我想要改变问题,这样他们每次都不会出现在同一个顺序中.
我在我的HTML代码中有这个:
<div ng-repeat="question in questions | filter:ids | orderBy:randomSort">
<div id="question">{{question.question}}</div><img id="nextImg" ng-src="../app/img/next.png" ng-click="next()" />
<img class="quizImg" ng-hide="{{question.image}}==null" ng-src="{{question.image}}" />
<div class="answer" ng-repeat="answer in question.answers">
<input type="radio" ng-click="checked(answer)">{{answer.answer}}
</div>
<!--input id="nextQuestion" type="button" ng-click="next()" value="{{buttonText}}"-->
</div>
Run Code Online (Sandbox Code Playgroud)
这在我的控制器中
lycheeControllers.controller('quizCtrl', ['$scope', '$http', function ($scope, $http) {
$http.get('json/questions.json').success(function (data) {
//all questions
$scope.questions = data;
$scope.titel = "Check your knowledge about lychees"
$scope.randomSort = function(question) {
return Math.random();
};
//filter for getting answers / question
$scope.ids = function (question) {
return question.id == …Run Code Online (Sandbox Code Playgroud) 请考虑以下示例:
angular.module('app', []).controller('TestController', function($scope) {
$scope.getText = function() {
console.log('getting text');
return 'text';
};
}).filter('text', function() {
return function() {
console.log('text filter');
return 'text';
};
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular.min.js"></script>
<div ng-app="app" ng-controller="TestController">
<p>{{getText()}}</p>
<p>{{'' | text}}</p>
</div>Run Code Online (Sandbox Code Playgroud)
请注意,该getText()函数运行两次,而过滤器只运行一次.我假设该getText()函数运行两次以确保模型现在稳定.为什么过滤器的行为不一样?
我正在努力让阵列显示我想要的样子.
我有:
$scope.array = [["one", "two", "three", "four"], "five"],["six", "seven", "three", "four"], "two"]];
Run Code Online (Sandbox Code Playgroud)
我想迭代并在第一个数组中显示字符串.我想展示:
一二三四有六七三四
目前我有以下内容:
<p ng-repeat="a in array">{{a[0]}}</p>
但它出现了:
["one", "two", "three", "four"]
["six", "seven", "three", "four"]
Run Code Online (Sandbox Code Playgroud)
我已经尝试了一个过滤器来删除引号等,但它不断拉起另一个数组.
因此,在超时 PARAM,一个线程,应停止后的线程超时秒(如果还没有终止).
在我的软件中,我正在尝试替换Queue.Queue.join()(它包含每个线程的项目:每个线程将运行Queue.Queue.task_done())如果线程没有终止可能会停止软件.因此,如果一个线程(除其他50之外)没有终止,那么它就会被冻结.
我希望每个线程在5秒内停止,例如.所以我将以超时5秒开始每个线程.这是对的吗?
码
import threading
import time
def tt(name, num):
while True:
num += 0.5
print 'thread ' + str(name) + ' at time ' + str(num)
time.sleep(0.5)
for i in range(3):
t=threading.Thread(target=tt, args=(i, 0))
t.setDaemon(True)
t.start()
t.join(timeout=1)
print 'end'
Run Code Online (Sandbox Code Playgroud)
结果
它没有正常工作..每个线程应在1秒后停止.线程0在3秒后停止,线程1在2秒后停止.
thread 0 at time 0.5
thread 0 at time 1.0
thread 1 at time 0.5
thread 0 at time 1.5
thread 0 at time 2.0
thread 1 at …Run Code Online (Sandbox Code Playgroud) 我有以下数据库(形式广泛)“ st_all”,在该数据库中有两个我想重塑的变量(“ P”和“ PLC”)。主题的ID为“ g_id”。
g_id study condition sample PLC1 PLC2 PLC3 PLC4 PLC5 PLC6 PLC7 PLC8 PLC9 PLC10 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10
1 1 1 1 1 20 20 20 50 50 20 30 20 50 50 1 2 2 1 2 2 1 1 1 1
2 2 1 1 1 60 70 50 70 60 60 60 70 60 50 1 2 1 1 2 2 1 1 1 1
3 …Run Code Online (Sandbox Code Playgroud) 我有一个 Angular 帖子到节点,根据响应代码我想执行不同的任务。
在我的节点中,我有 res.send 来根据操作节点端发回不同的响应代码。
我有一个小的 if else 语句,但它似乎只运行 200 响应代码,它不打印 400 或其他代码
我的代码
FirstModule.controller('LoginController', function($scope, $http) {
$scope.formData = {};
$scope.LoginForm = function() {
var data = {
LoginEmail: $scope.sometext.LoginEmail
};
$http({
url: 'http://localhost:8080/back-end/controller',
method: "POST",
data: data,
headers: {
'Content-Type': 'application/json'
}
}).then(function(response) {
if (response.status === 200) $scope.sometext = "200 all good";
else if (response.status === 400) $scope.sometext = "400 nope";
else if (response.status === 404) $scope.sometext = "404";
else if (response.status === 500) $scope.sometext = …Run Code Online (Sandbox Code Playgroud) 我试图访问我的服务器上的主要路线
完整的错误消息是:
未捕获错误:模块"AppModule"导入的意外指令"ProductsComponent".请添加@NgModule注释.at syntaxError(compiler.es5.js:1690)at compiler.es5.js:15382 at Array.forEach()at CompileMetadataResolver.webpackJsonp .../../../compiler/@angular/compiler.es5.js. CompitMetadataResolver.getNgModuleMetadata(compiler.es5.js:15365)位于JitCompiler.webpackJsonp .../../../compiler/@angular/compiler.es5.js.JitCompiler._loadModules(compiler.es5.js:26795)at at JitCompiler.webpackJsonp .../../../compiler/@angular/compiler.es5.js.JitCompiler.在PlatformRef的JitCompiler.webpackJsonp .../../../ compiler /@angular/compiler.es5.js.JitCompiler.compileModuleAsync(compiler.es5.js:26697)中编译模块和编译器(compiler.es5.js:26768). webpackJsonp .../../../core/@angular/core.es5.js.PlatformRef_.bootstrapModuleWithZone(core.es5.js:4536)位于 Object的PlatformRef .webpackJsonp .../../../core/@angular/core.es5.js.PlatformRef_.bootstrapModule(core.es5.js:4522). ../../../../../src/main.ts(main.ts:11)
其他路由器端点如
也给出了同样的错误
这是我的主文件
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { ProductsComponent } from './products/products.component';
import { CartComponent } from './cart/cart.component';
import { MenuComponent } from './menu/menu.component';
import { AppRoutingModule, …Run Code Online (Sandbox Code Playgroud) 我正在使用ng-repeat创建一个具有可扩展行的表。我应该能够一次扩展一个表行。如果我展开一行,则先前展开的行应关闭。如果需要其他详细信息,请告诉我。谢谢。
<tbody>
<tr ng-repeat-start="person in people">
<td>
<button ng-if="person.expanded" ng-click="person.expanded = false">-</button>
<button ng-if="!person.expanded" ng-click="person.expanded = true">+</button>
</td>
<td>{{person.name}}</td>
<td>{{person.gender}}</td>
</tr>
<tr ng-if="person.expanded" ng-repeat-end="">
<td colspan="3">{{person.details}}</td>
</tr>
</tbody>
Run Code Online (Sandbox Code Playgroud)