我需要迭代嵌套的json数组,看起来像那样
[
{
"title": "EPAM",
"technologies": [
"PHP",
".net",
"Java",
"Mobile",
"Objective-C",
"Python",
"Ruby"
],
"location": "Belarus",
"city": "Minsk"
},
{
"title": "Parallels",
"technologies": [
"PHP",
"Java",
"C++",
"iOS Development",
"C#",
"Ember.js"
],
"location": "Russia",
"city": "Moscow"
}
]
Run Code Online (Sandbox Code Playgroud)
我想要的是遍历每个公司的技术列表,然后返回一个唯一值列表.但是,我无法访问控制器中公司阵列中的单个公司.到目前为止看起来像这样
var app = angular.module('app', []);
app.controller('CompaniesController', ['$scope', '$http',
function($scope, $http) {
$http.get('json/companies.json').success(function(data) {
$scope.companies = data; // get data from json
$scope.techStack = []
$scope.companies = data.query(function(companies) {
console.log(companies); //I expected to see data here
});
});
}
]);
Run Code Online (Sandbox Code Playgroud)
显然我做错了什么.
我已经在根组件和模块配置中全局禁用了"向后滑动"
<ion-nav #appNav [root]="rootPage" swipeBackEnabled="false"></ion-nav>
...
IonicModule.forRoot(MobileApplication, {swipeBackEnabled: false}),
...
Run Code Online (Sandbox Code Playgroud)
我需要只为一页启用它.所以试图通过将nav实例传递给构造函数然后将swipeBackEnabled设置为true来设置它.
ionViewWillEnter() {
this.nav.swipeBackEnabled = true;
console.log('swipeBackEnabled ' + this.nav.swipeBackEnabled);
console.log('canGoBack ' + this.nav.canGoBack());
console.log('canSwipeBack ' + this.nav.canSwipeBack());
}
Run Code Online (Sandbox Code Playgroud)
记录swipeBackEnabled并且canGoBack返回true,但canSwipeBack返回false.如果我在模板中的某处添加滑动事件并在右侧滑动时记录这些值,则会将所有值记录为true.然而,没有任何反应,似乎刷回来不起作用?我错过了什么吗?
作为参考,我使用的是Ionic 3.9.2和@ ionic/app-scripts 3.1.4.提前致谢
我正在使用passport.js进行Facebook身份验证,并且最近开始出现此错误。完整的错误消息如下所示:
FacebookGraphAPIError: (#100) Tried accessing nonexisting field (user_photos) on node type
(User) at D:\app\node_modules\passport-facebook\lib\strategy.js:167:21 at passBackControl
(D:\app\node_modules\passport-facebook\node_modules\passport-oauth2\node_modules\oauth\lib\oauth2.js:124:9)
at IncomingMessage.<anonymous> (D:\app\node_modules\passport-facebook\node_modules\passport-oauth2\node_modules\oauth\lib\oauth2.js:143:7)
at IncomingMessage.emit (events.js:129:20) at _stream_readable.js:908:16 at
process._tickCallback (node.js:355:11)
Run Code Online (Sandbox Code Playgroud)
我尝试了其他方法来设置权限范围。最初我在
passport.use(new FacebookStrategy({
profileFields : ['user_photos', 'user_friends'],
}
Run Code Online (Sandbox Code Playgroud)
然后我将其移至
app.get('/auth/facebook', passport.authenticate('facebook',
{ scope : ['email, public_profile, user_photos, user_friends'] }));
Run Code Online (Sandbox Code Playgroud)
而且,如果我删除user_photos,它还会导致相同的错误,以及user_friends。关于我在做什么错的任何想法吗?我的身份验证脚本的核心受到本教程https://scotch.io/tutorials/easy-node-authentication-facebook的启发
我正在尝试制作小型图片库。在:hover上,每个图像的左侧都应显示一个工具提示。我的HTML代码如下所示:
.gallery {
right: 247px;
width: 220px;
}
.gallery li {
display: inline;
width: 100px;
height: 100px;
position: relative;
}
.gallery img {
float: right;
margin: 10px;
box-shadow: 0 0 0 8px rgba(0, 0, 0, 0.3);
-webkit-background-clip: padding-box;
/* for Safari */
background-clip: padding-box;
/* for IE9+, Firefox 4+, Opera, Chrome */
}
.tooltip {
width: 300px;
height: 100px;
display: none;
position: absolute;
right: -108px;
top: 222px;
z-index: 70;
background-color: rgba(0, 0, 0, 0.4);
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(opacity=40)";
}
.gallery li:hover>.tooltip { …
Run Code Online (Sandbox Code Playgroud)我试图在控制器中的函数内部触发angularJS路由,但它会抛出"Uncaught TypeError:无法读取未定义的属性'路径'".无法真正看到我错过了$ location注入的位置,猜测它的原因.
var gameApp = angular.module('gameApp', ['ngRoute']);
gameApp.config(function($routeProvider, $locationProvider, $provide) {
$locationProvider.html5Mode(true);
$routeProvider
// route for the home page
.when('/', {
templateUrl : 'home.html',
controller : 'mainController'
})
// route for the game page
.when('/game', {
templateUrl : 'game.html',
controller : 'gameController'
})
// route for the game over page
.when('/game-over', {
templateUrl : 'game-over.html',
controller : 'mainController'
})
// default
.otherwise({
redirectTo: '/'
});
});
Run Code Online (Sandbox Code Playgroud)
当我使用路由器时,我的游戏控制器的一部分
gameApp.controller('gameController', ['$scope', '$location', function($scope, $location){
function gameLost($location){
var check = false;
console.log …
Run Code Online (Sandbox Code Playgroud) 我正在尝试以 angular 实现服务组件通信,当服务持有一个值并且组件订阅它时会发生变化。我正在使用 rxjs 订阅,但我得到了
Uncaught (in promise): Error: No provider for Subscription!
Run Code Online (Sandbox Code Playgroud)
这是我在服务中所做的事情:
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { Subject } from 'rxjs/Subject';
@Injectable()
export class PracticeContextService {
practice: Subject<any> = new Subject<any>();
public practiceSelected$ = this.practice.asObservable();
setPractice(providerId: string) {
this.practice.next({ providerId: providerId });
}
getPractice(): Observable<any> {
return this.practice.asObservable();
}
}
Run Code Online (Sandbox Code Playgroud)
并在组件中:
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
import { PracticeContextService } …
Run Code Online (Sandbox Code Playgroud)