我开始使用MEAN.JS并尝试在Angular Bootstrap示例页面上实现轮播示例.我使用命令yo meanjs创建了一个样板项目,并修改了home.client.view.html以删除jumbotron并将其替换为以下html(从ui bootstrap示例中复制)
<div ng-controller="MyCarouselController">
<div style="height: 305px">
<carousel interval="myInterval">
<slide ng-repeat="slide in slides" active="slide.active">
<img ng-src="{{slide.image}}" style="margin:auto;">
<div class="carousel-caption">
<h4>Slide {{$index}}</h4>
<p>{{slide.text}}</p>
</div>
</slide>
</carousel>
</div>
<div class="row">
<div class="col-md-6">
<button type="button" class="btn btn-info" ng-click="addSlide()">Add Slide</button>
</div>
<div class="col-md-6">
Interval, in milliseconds: <input type="number" class="form-control" ng-model="myInterval">
<br />Enter a negative number to stop the interval.
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我添加了一个名为MyCarouselController的控制器(文件名为carousel.client.controller.js)并从示例中添加了javascript
angular.module('core').controller('MyCarouselController', ['$scope', 'Authentication',
function($scope, Authentication) {
$scope.myInterval = 5000;
var slides …Run Code Online (Sandbox Code Playgroud) 当我使用命令时: npm install -g bower
我收到此错误:
npm ERR! tar.unpack untar error /home/ec2-user/.npm/bower/1.3.12/package.tgz
npm ERR! Linux 3.14.20-20.44.amzn1.x86_64
npm ERR! argv "node" "/usr/local/bin/npm" "install" "-g" "bower" "-F"
npm ERR! node v0.10.34
npm ERR! npm v2.1.14
npm ERR! path /usr/local/lib/node_modules/bower
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/bower'
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules/bower']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules/bower',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/bower',
npm ERR! …Run Code Online (Sandbox Code Playgroud) 我是 Mongodb 的新手,并且在我使用 MEAN 堆栈构建的 Web 应用程序中使用它。我的目标是通过连接两个表并对它们应用过滤条件来查询它们。例如:我有两个表 - 自行车-自行车 ID、注册号、品牌、型号和预约 - 预约日期、状态、自行车(参考自行车对象),我只想显示那些没有预约状态=的自行车“已预订”。我想在 Mongoose 中完成以下 SQL。
Select bike.* from Bike inner join Appointment on Bike.BikeID = Appointment.BikeID and Appointment.Status != 'Booked'
Run Code Online (Sandbox Code Playgroud)
我正在使用以下代码,但没有得到所需的结果。有人可以帮我解决这个问题吗?
app.get('/api/getbikeappo*',function(req,res){
var msg="";
//.find({cust:req.query._id})
//.populate('cust','email')
ubBike.aggregate([
{
$match:
{
cust : req.query._id
}
},
{
$lookup:
{
from: "appos",
localField: "_id",
foreignField: "bike",
as : "appointments"
}
},
{
$match:
{
"appointments" : {$eq : []}
}
}
])
.exec(function(err,bikes){
res.send(bikes);
if(err) throw err;
});
});
Run Code Online (Sandbox Code Playgroud)
bikes - collection …Run Code Online (Sandbox Code Playgroud) mongoose mongodb aggregation-framework mean-stack mongodb-aggregation
我正在开发一个 MEAN 应用程序。过去我只使用 Angular,ng-serve 是尝试代码和开发的福音。
现在结合 Node.js 作为服务器,在我所谓的“公共”文件夹中加载 Angular,我每次都必须执行“ng build”,它确实会遍历所有文件,即使我只是更改了一些代码在一个组件 Typescript 上。
我的问题?我该如何使用 Node.js 和 Angular 2 更快地进行开发,而不必每次都在更改的代码上进行“ng build”?
这似乎是一个简单的问题,但我认为没有什么对我有用.我的component.html中有一个标准输入字段:
<div class="form-group">
<label>Serial</label>
<input type="text" name="serial" id="serial" [ngModel]="serial" [value]="serial" class="form-control">
</div>
Run Code Online (Sandbox Code Playgroud)
因此,当用户现在提交表单时,如何获得他在字段中输入的值?如果我console.log(this.serial)在我的onSubmit()功能中做一个简单的事情,我什么也得不到.我serial: String;在我的组件中声明了
我正在尝试将元素推送到 mongoose 中的数组。我正在用更新和 $push 来做。但它没有在数据库中更新它。这是我的代码。路线.js:
var Chooser = require('../chooser');
var appRouter = function(app) {
app.put("/chooser/:id", function(req, res) {
console.log("ID: ", req.params.id);
if (!req.body.toFollow) {
return res.send({"status": "error", "message": "The account that you want to follow is needed"});
}
else {
console.log("Cuenta: ", req.body.toFollow);
Chooser.update({_id: req.params.id}, {$push: {accounts: {"name": "foo", "idAccount": 123456}}});
return res.send({"status": "ok"});
}
});
}
Run Code Online (Sandbox Code Playgroud)
这是我的猫鼬模式。选择器.js:
var mongoose = require('mongoose');
var chooserSchema = mongoose.Schema({
_id: Number,
accounts: [{name: String, idAccount: Number}]
}, { _id: false });
var Chooser …Run Code Online (Sandbox Code Playgroud) 我正在学习 MEAN 堆栈并且我被困在一段曾经可以工作的代码上,但出于某种原因,今天它似乎不想为我工作。
我收到错误消息:“类型 Observable 不可分配给类型 Observable。您是想改用‘any’类型吗?
这是出现错误的 course.service.ts 文件:
import { Injectable } from '@angular/core';
import {Course} from './course';
import {Observable} from 'rxjs/Observable';
import {HttpClient} from '@angular/common/http';
@Injectable() export class CourseService {
constructor(private httpClient: HttpClient) { }
readAll(): Observable<Course[]> {
return this.httpClient
.get('https://jsonplaceholder.typicode.com/posts'); }
}
Run Code Online (Sandbox Code Playgroud)
这是course.component.ts:
import {Component, Input, OnInit} from '@angular/core';
import {Course} from '../course';
@Component({
selector: 'app-course',
templateUrl: './course.component.html',
styleUrls: ['./course.component.css']
})
export class CourseComponent implements OnInit {
@Input()
course: Course;
@Input()
courseItemCss: string;
constructor() { } …Run Code Online (Sandbox Code Playgroud) I am using Angular 2 flash messages to display message when user click on logout button. I have added provider in navbar.component.ts, and some other experiments but facing same error.
Below are the steps which i have performed:
Step1:
npm install angular2-flash-messages --save
Run Code Online (Sandbox Code Playgroud)
Step2: app.module.ts
import { FlashMessagesModule } from 'angular2-flash-messages';
@NgModule({
imports: [
// other imports
// ...
FlashMessagesModule,
// ...
]
})
Run Code Online (Sandbox Code Playgroud)
Step3: app.component.html
<app-navbar></app-navbar>
<div class="container">
<flash-messages></flash-messages>
<router-outlet></router-outlet>
</div>
Run Code Online (Sandbox Code Playgroud)
Step4: navbar.component.ts
import { Component} from '@angular/core';
import …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的服务器中上传图像。在前端,我正在使用 Angular。 前端工作正常,我发布只是为了向您展示我如何将文件传递给后端!
组件.html
<div fxLayout="column" fxLayoutAlign="center center">
<div>
<mat-form-field>
<ngx-mat-file-input placeholder="Only photos" [accept]="'.jpg, .jpeg, .png'" (change)="onChange($event)"></ngx-mat-file-input>
</mat-form-field>
</div>
<div>
<button mat-button (click)="onSubmit()">Send</button>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
component.ts - 函数
imagem: File;
constructor(private uploadService: UploadService) { }
onChange(event) {
this.imagem = event.target.files[0];
}
onSubmit() {
this.uploadService.upload(this.imagem);
}
Run Code Online (Sandbox Code Playgroud)
upload.service.ts - 函数
constructor(private http: HttpClient) { }
upload(file: File) {
const formData = new FormData();
formData.append('img', file, file.name);
this.http.post(environment.apiBaseUrl + '/upload', formData, {responseType: 'text'}).subscribe(
res => console.log('Done')
);
}
Run Code Online (Sandbox Code Playgroud)
在后端,我有这样的结构:
应用程序.js
const express = …Run Code Online (Sandbox Code Playgroud) 我正在使用Express、EJS和 MongoDB 开发博客应用程序(单击链接以查看GitHub 存储库)。
我为帖子制作了一个简单的寻呼机。
在帖子控制器中,我有:
exports.getPosts = async (req, res, next) => {
const posts = await Post.find({}, (err, posts) => {
const perPage = 10;
const currPage = req.query.page ? parseInt(req.query.page) : 1;
const postsCount = posts.length;
const pageCount = Math.ceil(postsCount / perPage);
const pageDecrement = currPage > 1 ? 1 : 0;
const pageIncrement = currPage < pageCount ? 1 : 0;
if (err) {
console.log("Error: ", …Run Code Online (Sandbox Code Playgroud) mean-stack ×10
angular ×4
javascript ×4
node.js ×4
mongodb ×2
mongoose ×2
typescript ×2
amazon-ec2 ×1
angularjs ×1
bower ×1
ejs ×1
express ×1
multer ×1