我们如何动态添加/更新元标记,以便它们被Facebook/Whatsapp共享对话框选中?
我将angular 2应用程序升级为angular 4,以便在我们从API获取组件中的数据后,使用Meta服务动态添加/更新元标记.
到目前为止,在我的组件中,我有
this.metaService.updateTag({ property: 'og:title', content: pageTitle });
this.metaService.updateTag({ property: 'og:url', 'www.domain.com/page' });
this.metaService.updateTag({ property: 'og:image', content: coverUrl, itemprop: 'image' });
this.metaService.updateTag({ property: 'og:image:url', content: coverUrl, itemprop: 'image' });
this.metaService.updateTag({ property: 'og:image:type', content: 'image/png' });
Run Code Online (Sandbox Code Playgroud)
我正在使用updateTag,因为我已经添加了带有默认值的静态标记.当我检查元代码时,此代码会成功更新元标记值.
我知道Facebook/Whatsapp调试工具不执行任何javascript是有道理的,所以它不会在他们的环境中执行.
我正在使用https://developers.facebook.com/tools/debug/它,它总是选择有意义的默认标签值.
我的问题是,Facebook/Whatsapp动态获取更新的标签值的方法是什么?我正在使用Angular 4并通过API调用加载所有数据,因此在页面加载和脚本执行之前无法获取任何类型的数据.
我正在使用依赖注入编写web api,在存储库的帮助下工作单元和Autofac作为容器.依赖性在24小时前被完美注入,但突然间,当我今天开始工作时,我一直收到错误
"消息":"发生错误.","ExceptionMessage":"尝试创建'SearchController'类型的控制器时发生错误.确保控制器具有无参数的公共构造函数.","ExceptionType":" System.InvalidOperationException"
我将包括我的签名以及我如何注册类型,如果有人可以指出我的代码可能出错,我将非常高兴.
在我的网络api控制器上,我有
private IUnitOfWork<Listing> _unitOfWork = null;
public SearchController(IUnitOfWork<Listing> unitOfWork)
{
_unitOfWork = unitOfWork;
}
Run Code Online (Sandbox Code Playgroud)
工作单元采用泛型类型参数来创建存储库.
在我的WebApiConfig.cs中,我正在注册以下类型
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
builder.RegisterGeneric(typeof(UnitOfWork<>)).As(typeof(IUnitOfWork<>)).InstancePerDependency();
builder.RegisterType(typeof(SearchController)).UsingConstructor(typeof(IUnitOfWork<Listing>));
Run Code Online (Sandbox Code Playgroud)
我正在注册SearchController以使用接受IUnitOfWork <>的构造函数.在我添加Mocked单元测试之前一切正常,但出于某种目的,我现在继续得到这个错误.我还注册了DependencyResolver
var container = builder.Build();
var resolver = new AutofacWebApiDependencyResolver(container);
config.DependencyResolver = resolver;
Run Code Online (Sandbox Code Playgroud) c# dependency-injection unit-of-work autofac asp.net-web-api2
我试图使用ASP.NET MVC(不是核心)与AngularJS 2和路由的一些问题.
首先在RouteConfig.cs中,我定义了以下路由
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
// when the user types in a link handled by client side routing to the address bar
// or refreshes the page, that triggers the server routing. The server should pass
// that onto the client, so Angular can handle the route
routes.MapRoute(
name: "spa-fallback",
url: "{*url}",
defaults: new { controller = "Home", action = "Index" } …Run Code Online (Sandbox Code Playgroud) 我在角度2应用程序中使用primeng并面临此问题(stackoverflow问题)
虽然在接受的答案中提供的plunkr有效但在我的场景中没有.我有一个单独的组件,它根据父组件的输入加载.我希望在子组件关闭/隐藏时切换可见性标志.
这是代码片段
<p-dialog header="Assets Management" [(visible)]="showDialog" modal="modal" [closable]="true" (onHide)="close()" appendTo="body">
.. some content ..
</p-dialog>
Run Code Online (Sandbox Code Playgroud)
在组件中,我有:
@Component({
selector: 'view-car-colors',
templateUrl: '/view-car-colors.html',
inputs: ['showDialog'],
outputs: ["onCloseDialog"],
})
export class ViewCarColorsComponent {
private showDialog: boolean = false; //default close
private onCloseDialog: EventEmitter<any> = new EventEmitter();
public close(): void {
this.showDialog = false;
//emit this to its parent
this.onCloseDialog.emit({ hasChanges: true });
}
}
Run Code Online (Sandbox Code Playgroud)
最后在我的父组件中,我称之为:
<view-car-colors [showDialog]="showCarColorsDialog" (onCloseDialog)="onCarColorsCloseDialog($event)"></view-car-colors>
Run Code Online (Sandbox Code Playgroud)
当showCarColorsDialog基于点击一个按钮改变.
private onCarColorsCloseDialog($event: any): void {
this.showCarColorsDialog = false;
if ($event.hasChanges) …Run Code Online (Sandbox Code Playgroud) 是否可以通过Webbrowser控件(内置)连接一个事件?我需要在桌面应用程序中执行oAuth,我需要知道验证码是否已添加到redirect_uri.
我正在使用内置的WebBrowser控件并具有导航和导航等事件,但我遇到了关于ieframe.dll/navcancl.htm的问题,所以我决定使用CefSharp.wpf ChromiumWebBrowser,但我无法找到浏览器导航到URL后可以调用的任何事件.
这就是我在xaml中所做的
<wpf:ChromiumWebBrowser Grid.Row="0" Grid.Column="0"
x:Name="ChromiumBrowser"
WebBrowser="{Binding WebBrowser, Mode=OneWayToSource}" FrameLoadStart="ChromiumBrowser_OnFrameLoadStart"
Title="{Binding Title, Mode=TwoWay}" />
Run Code Online (Sandbox Code Playgroud)
当用户请求进行身份验证时,我将地址设置为
ChromiumBrowser.Address = NavigateUrl
Run Code Online (Sandbox Code Playgroud) 我在app模板(根组件的模板)中定义了一个spinner/loader元素
<!--I have it here so that I don't have to paste it in all my templates-->
<div #spinner></div>
Run Code Online (Sandbox Code Playgroud)
在我的子组件中,我试图使用它来访问它,@ViewChild但似乎总是返回undefined.我在子组件中访问它的代码是
@ViewChild('spinner', { read: ViewContainerRef }) container: ViewContainerRef; //this is always undefined
Run Code Online (Sandbox Code Playgroud)
但是,当我将我#spinner的子组件的HTML 放入其中时,它会被正确地拾取.
有没有办法将子组件中父组件中定义的元素作为一个ContainerRef?
我需要视图引用来动态地使用它创建组件ComponentFactoryResolver.
这似乎是一个类似的问题,但无法找到克服的方法.
编辑:我现在使用与observable的共享服务,但它仍然没有引发事件.next.
这是我的代码 SpinnerComponent
@Component({
selector: 'spinner',
styleUrls: ['app/styles/spinner.component.css'],
template:
`<div [hidden]="state.visible" class="in modal-backdrop spinner-overlay"></div>
<div class="spinner-message-container" aria-live="assertive" aria-atomic="true">
<div class="spinner-message" [ngClass]="spinnerMessageClass">{{ state.message }}</div>
</div>`
})
export class SpinnerComponent {
constructor(spinnerService: SpinnerService) { …Run Code Online (Sandbox Code Playgroud) 我将 angular 2 与primeng p-dropdown 一起使用,并且有一个案例,当用户选择父项时,我需要过滤子项下拉列表。我是用自定义管道做的
<p-dropdown [options]="carTypesOptions" [(ngModel)]="CarTypeId" name="CarTypeId"></p-dropdown>
<p-dropdown [options]="carMakeOptions | filterCarMakes: CarTypeId" [(ngModel)]="CarMakeId" name="CarMakeId"></p-dropdown>
Run Code Online (Sandbox Code Playgroud)
因此,当用户选择汽车类型时,我将使用采用 CarTypeId(父选定 ID)的 filterCarMakes 管道过滤第二个下拉列表。这一切都很好。这是我的filterCarMakes管子。
@Pipe({
name: 'filterCarMakes',
pure: false
})
export class FilterMakesPipe implements PipeTransform {
transform(carMakesOptions: CarMakeSelectItem[], carTypeId: string): CarMakeSelectItem[] {
if (!carTypeId)
return carMakesOptions.filter(p => p.carTypeId == null);
//perform some filtering operation
return filteredCarMakeOptions;
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,如果我将 console.log 放入管道中,它会继续非常快速地在控制台上记录该消息(例如每 100 毫秒一次),这意味着即使 parent 的值没有更改,它也会继续调用。这样做的副作用是,如果有滚动,我无法在子下拉列表中选择任何值,因为它会继续刷新选项。
过滤下拉列表的简单屏幕截图如下(它不会让我滚动选择其他值并会继续刷新)
PS:我不想在 onChange 事件中执行它并从组件调用管道,那么是否可以在模板中执行它?
我有一个场景,其中我有包含javascript,css和html的完整网页。我需要完全删除脚本和样式标签及其内容。我已经在PHP中使用以下正则表达式实现了这一点:
$str = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $html);
preg_replace('#<style(.*?)>(.*?)</style>#is', '', $str);
Run Code Online (Sandbox Code Playgroud)
但是无法用javascript完成。我想拥有相当于
<script(.*?)>(.*?)</script> //in javascript
Run Code Online (Sandbox Code Playgroud)
我想替换它们在html中的所有出现。我已经用这个剥离了其他html标签
pureText.replace(/<(?:.|\n)*?>/gm, ''); //just a reference
Run Code Online (Sandbox Code Playgroud) 我有一个听起来可能很愚蠢的场景,但是我被困住了,试图理解是什么导致了它不起作用。
我有一个现在有三个模块的角度应用程序
var app = angular.module('mainApp', ['ngRoute']); //parent module
var reviewModule = angular.module('reviewModule', ['mainApp']); //child 1
var searchmodule = angular.module('searchmodule', ['mainApp']); //child 2
Run Code Online (Sandbox Code Playgroud)
我已经在我的父模块(即mainApp)中设置了一些配置和默认字符串,我希望在其所有子模块中使用它。
另一方面,我的reviewModule和searchmodule(子模块)具有单独的控制器和服务,这些控制器和服务在不同的路线上使用。现在,问题来了,当我想将一个模块的服务用于另一个模块时,例如,如果我执行以下操作
var searchmodule = angular.module('searchmodule', ['mainApp', 'reviewModule']);
Run Code Online (Sandbox Code Playgroud)
在我的搜索模块控制器中使用reviewModule服务时,出现一个异常提示
Error: $injector:modulerr Module Error
Failed to instantiate module searchmodule
Run Code Online (Sandbox Code Playgroud)
两个子模块都具有相同的父模块,我想将一个子模块用于另一个子模块,并且不明白为什么会收到此异常。
更新:
我什至尝试使用以下行进行模块声明
var searchmodule = angular.module('searchmodule', ['reviewModule']);
Run Code Online (Sandbox Code Playgroud)
但这也会引起异常。
angularjs angularjs-scope angular-services angular-controller angular-module
angular ×5
c# ×2
primeng ×2
angular-pipe ×1
angularjs ×1
asp.net-mvc ×1
autofac ×1
cefsharp ×1
html ×1
javascript ×1
meta-tags ×1
oauth-2.0 ×1
regex ×1
unit-of-work ×1
wpf ×1