我们有一个企业应用程序,它为客户端使用Angular 2.我们每个客户都有自己独特的网址,例如:https://our.app.com/customer-one和https://our.app.com/customer-two.目前我们可以<base href...>动态设置document.location.所以用户点击https://our.app.com/customer-two并<base href...>设置为/customer-two......完美!
问题是,如果用户是例如,https://our.app.com/customer-two/another-page并且他们刷新页面或尝试直接点击该URL,则<base href...>设置为get /customer-two/another-page并且找不到资源.
我们尝试了以下无济于事:
<!doctype html>
<html>
<head>
<script type='text/javascript'>
var base = document.location.pathname.split('/')[1];
document.write('<base href="/' + base + '" />');
</script>
...
Run Code Online (Sandbox Code Playgroud)
不幸的是,我们的想法很新鲜.任何帮助都会很棒.
使用以下表达式我期望Angular通过日期管道插入日期(如果不是null),但是我得到了进行中的错误.
{{charge.offenseDate ? charge.offenseDate | date : 'No date'}}
EXCEPTION: Error: Uncaught (in promise): Template parse errors:
Parser Error: Conditional expression {{charge.offenseDate ? charge.offenseDate | date : 'No Date' }} requires all 3 expressions at the end of the expression
Run Code Online (Sandbox Code Playgroud)
是我期待的可能,或者只是... 管梦 :)
我有一个自定义输入组件,正在更新验证和状态,触摸/未触摸除外.其他所有状态(原始/肮脏)都按预期工作.
这是一个吸烟者:https://plnkr.co/edit/O9KWzwhjvySnXd7vyo71
import { Component, OnInit, Input, ElementRef, forwardRef, Renderer } from '@angular/core';
import { REACTIVE_FORM_DIRECTIVES, Validator, Validators, NG_VALUE_ACCESSOR, ControlValueAccessor} from '@angular/forms';
export const CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR: any = /*@ts2dart_const*/ {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => CustomInputComponent),
multi: true
};
const noop = () => {};
@Component({
selector: 'my-custom-input',
providers: [CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR],
template: `
<div class="form-group">
<label>CUSTOM INPUT</label>
<input type="text" class="form-control" [(ngModel)]="value" required>
<p *ngIf="control.errors.required && control.touched">Field is required</p>
<strong>Has input been touched: {{control.touched ? 'Yes' : 'No'}}</strong><br>
<strong>Is input untouched: …Run Code Online (Sandbox Code Playgroud) 我坚持如何ngModel使用指令访问和更改输入值.问题的结果是,当我选择所需的地址时,模型的地址值不会更新...它只是设置为我实际键入输入的内容,而不是输入的最终值.
我键入'830':
我选择'8300 Fauntleroy Way Southwest,Seattle,WA,United States':
结果价值:
{
address: '830'
}
Run Code Online (Sandbox Code Playgroud)
期望值:
{
address: '8300 Fauntleroy Way Southwest, Seattle, WA, United States'
}
Run Code Online (Sandbox Code Playgroud)
在AngularJS中,我可以这样做:
(function() {
'use strict';
angular
.module('casemanagerApp')
.directive('googleplace', googleplace);
function googleplace() {
var directive = {
require: 'ngModel',
link: link
};
return directive;
function link(scope, element, attrs, model) {
var options = {
types: [],
componentRestrictions: {}
};
scope.gPlace = new google.maps.places.Autocomplete(element[0], options); // jshint ignore:line
google.maps.event.addListener(scope.gPlace, 'place_changed', function() { // jshint ignore:line
scope.$apply(function() …Run Code Online (Sandbox Code Playgroud) 在IE中,当我更新或销毁列表中的项目时,操作成功,但更新的列表/数据不会从服务器返回,因此列表未在视图中更新.
我试过以下无济于事:
angular.module('casemanagerApp')
.config(function($stateProvider, $urlRouterProvider, RestangularProvider) {
if (!RestangularProvider.setDefaultHeaders) {
RestangularProvider.setDefaultHeaders({});
}
RestangularProvider.setDefaultHeaders({'If-Modified-Since': 'Mon, 26 Jul 1997 05:00:00 GMT'});
RestangularProvider.setDefaultHeaders({'Cache-Control': 'no-cache'});
RestangularProvider.setDefaultHeaders({'Pragma': 'no-cache'});
$stateProvider
...
});
Run Code Online (Sandbox Code Playgroud)
有人能指出我正确的解决方案吗?