我有一个简单的方法,在它的最后我想重定向到另一个组件:
export class AddDisplay{
display: any;
addPairTo(name: string, pairTo: string){
this.display = {};
this.display.name = name;
this.display.pairTo = pairTo;
}
}
Run Code Online (Sandbox Code Playgroud)
我想做的是在方法结束时重定向到另一个组件:
export class AddDisplay{
display: any;
addPairTo(name: string, pairTo: string){
this.display = {};
this.display.name = name;
this.display.pairTo = pairTo;
this.redirectTo('foo');
}
}
Run Code Online (Sandbox Code Playgroud)
我如何在Angular 2中实现这一目标?
我已经阅读了新Angular路由器的文档.他们用于路由到变量的示例如下:
组件/模块:
angular.module('myApp', ['ngFuturisticRouter'])
.controller('AppController', ['$router', function($router) {
$router.config({ path: '/user/:id' component: 'user' });
this.user = { name: 'Brian', id: 123 };
});
Run Code Online (Sandbox Code Playgroud)
HTML /模板:
<div ng-controller="AppController as app">
<a router-link="user({id: app.user.id})">{{app.user.name}}</a>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的组件:
@RouteConfig([
{ path: '/', component: Home, as: 'home' },
{ path: '/displays/:id', component: DisplayDetails, as: 'display-details' }
])
Run Code Online (Sandbox Code Playgroud)
我的HTML /模板:
<div class="col-md-3" *ng-for="#display of displays">
<a [router-link]="['/display-details({id: display.id})']"><display-card ></display-card></a>
</div>
Run Code Online (Sandbox Code Playgroud)
我也试过而不是把组件别名(display-details)
我尝试将实际路径和组件放在自己身上,但它们都给了我同样的错误:
EXCEPTION: Component "App" has no route named "display-details({id: display.id})". in [null]
Run Code Online (Sandbox Code Playgroud) 我只是测试Angularjs2.0但是我遇到了向一个类注入服务的问题.这是我的代码:
import {Component, View, bootstrap, NgFor, HttpService, Promise} from 'angular2/angular2';
@Component({
selector: 'meeting-form',
appInjector: [MeetingService]
})
@View({
template: `
<ul>
<li *ng-for="#meeting of meetings">
Meeting Room: meeting room {{meeting.room}}
Date: {{meeting.date}}
Time: {{meeting.time}}
</li>
</ul>
<select #room>
<option value="1">Meeting Room 1</option>
<option value="2">Meeting Room 2</option>
</select>
<input type="date" #date>
<input type="time" #time>
<button (click)="reserveMeeting(room.value, date.value, time.value)">Reserve</button>
`,
directives: [NgFor]
})
class MeetingFormComponent{
meetings: Array;
constructor(meetingService: MeetingService){
this.meetings = meetingService.getMeetings();
}
reserveMeeting(room: number, date: string, time: string, meetingService: MeetingService){
meetingService.postMeeting(room, date, …
Run Code Online (Sandbox Code Playgroud) 我正在努力学习React,但这让我陷入困境:
<script type="text/jsx">
var Avatar = React.createClass({
render: function(){
return {
<div>
<img src={this.props.path}>
</div>
}
}
});
React.render(<Avatar path="img"/>, document.body);
</script>
Run Code Online (Sandbox Code Playgroud)
我一直收到这个错误:
Uncaught Error: Parse Error: Line 5: Unexpected token <
at http://localhost:420/
<div>
^
Run Code Online (Sandbox Code Playgroud)
我已经尝试将它包装在另一个div或span中但没有任何效果我做错了什么?
我想知道是否有任何方法可以让我创建自定义的 ember-data 方法,以便我可以执行以下操作:
this.store.customMethod('klass')
我知道我可以根据我的需要覆盖现有的方法,但我需要更多的控制权
我有一个简单的搜索输入,可以过滤通过html表中表示的api响应.过滤效果很好,但由于某些原因,我觉得这是一个非常难看的方式.所以我想知道什么是更好的方法.
这是我的控制器:
export default Ember.ArrayController.extend({
searchKeyword: null,
searchResults: function(){
var searchText = this.get('searchText');
if( ! searchText) return;
//YOUVE ALREADY GOT THE COMPANIES DONT GO BACK TO THE SERVICE
var companies = this.get('model');
var regex = new RegExp(searchText, 'i');
return companies.filter(function(company){
return company.name.match(regex);
});
}.property('searchText', 'model')
});
Run Code Online (Sandbox Code Playgroud)
这是我的路线:
export default Ember.Route.extend(AuthenticatedRouteMixin, {
model: function(){
var adapter = AddressBookHomeAdapter.create();
var companies = adapter.findAll();
return companies;
}
});
Run Code Online (Sandbox Code Playgroud)
这是我的适配器(我没有使用Ember-Data):
export default Ember.Object.extend({
findAll: function(){
return ajax('http://localhost:8000/api/v1/companies')
.then(function(response){
return response.data;
});
}
});
Run Code Online (Sandbox Code Playgroud)
这是非常丑陋的(在我看来)html …
我有2个组件,一个是a Topbar
,第二个是Display
这里它们是:
显示:
import {Component, View, NgIf} from 'angular2/angular2';
import {Topbar} from '../topbar/topbar';
@Component({
selector: 'display'
})
@View({
templateUrl: './components/display/display.html',
styleUrls: ['./components/display/display.css'],
directives: [Topbar, NgIf]
})
export class Display {
showGrid: boolean;
constructor(){
this.showGrid = true;
}
}
Run Code Online (Sandbox Code Playgroud)
显示HTML(对我的问题很重要):
<topbar></topbar>
<div *ng-if="showGrid" class="display-list">
<h1>true</h1>
</div>
<div *ng-if="showGrid == false" class="display-list">
<h1>false</h1>
</div>
Run Code Online (Sandbox Code Playgroud)
如你所见,我有一个if语句取决于showGrid
属性.现在这是我的Topbar组件:
顶栏:
import {Component, View} from 'angular2/angular2';
import {ROUTER_DIRECTIVES} from 'angular2/router';
@Component({
selector: 'topbar'
})
@View({
templateUrl: './components/topbar/topbar.html',
styleUrls: ['./components/topbar/topbar.css'],
directives: [ROUTER_DIRECTIVES]
}) …
Run Code Online (Sandbox Code Playgroud) 尝试安装时pdftk
apk
抛出此错误。
ERROR: unsatisfiable constraints:
pdftk (missing):
required by: world[pdftk]
Run Code Online (Sandbox Code Playgroud)
这是整个输出:
/opt/app # apk add pdftk
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
pdftk (missing):
required by: world[pdftk]
Run Code Online (Sandbox Code Playgroud)
我是 apk 新手,不确定问题的含义或如何解决它。
尝试将Laravel 5应用程序部署到Heroku时,我遇到了一个非常奇怪的错误.如果我尝试访问我的根域,https://my-app.herokuapp.com
它工作正常.但是,如果我尝试访问和其他域名/
也是https://my-app.herokuapp.com/api/v1/users
它给我一个404找不到.Heroku实际上是试图转到文件夹/ api/v1/users而不是读取路由文件.
这是我的Procfile:
web: vendor/bin/heroku-php-nginx public/
现在,如果我尝试相同的东西,但使用Apache服务器,它工作正常:
web: vendor/bin/heroku-php-apache2 public/
我有这样的字符串ClientLovesProcess
我需要在每个大写字母之间添加一个空格,除了第一个大写字母,所以最终结果将是这个Client Loves Process
我不认为golang有最好的字符串支持,但这就是我考虑去做的事情:
首先遍历每个字母,如下所示:
name := "ClientLovesProcess"
wordLength := len(name)
for i := 0; i < wordLength; i++ {
letter := string([]rune(name)[i])
// then in here I would like to check
// if the letter is upper or lowercase
if letter == uppercase{
// then break the string and add a space
}
}
Run Code Online (Sandbox Code Playgroud)
问题是我不知道如何检查字母是低于还是大写.我检查了字符串手册,但他们没有一些功能.什么是另一种完成这项工作的方法?
javascript ×5
angular ×4
ember.js ×2
alpine-linux ×1
deployment ×1
ember-cli ×1
ember-data ×1
go ×1
heroku ×1
laravel ×1
linux ×1
php ×1
reactjs ×1
routing ×1
string ×1
typescript ×1