我可以使用 Angular 将客户端行为注入 Umbraco 7 后台吗? [英] Can I inject a client-side behaviour into the Umbraco 7 back-office using Angular?

查看:19
本文介绍了我可以使用 Angular 将客户端行为注入 Umbraco 7 后台吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用定制的 Umbraco 安装,当他们第一次点击某些类型的内容时,我需要运行一些额外的用户交互.在实践中,这将弹出一个框,允许他们在将发布的内容共享给第三方服务时使用自定义消息.

I'm working with a customised Umbraco installation and I have a situation where I need to run a little extra user interaction when they click the 'Publish' button for the first time with certain types of content. In practice this will be to pop up a box that allows them to use a custom message when sharing the published content to a third-party service.

虽然我精通 Javascript,但我并没有花很多时间在 Angular 上,而且我所做的事情相当直接.

Although I am well versed in Javascript, I haven't spent a lot of time with Angular and what I have done has been fairly straight down the line.

在这种情况下,编辑器使用 Umbraco 内置的标准 Angular 控制器 - 理想的是挂钩到该范围并在提交表单时添加事件处理程序,但我不知道如何访问它,我怀疑它可能根本不可能.

In this case the editor uses the standard Angular controller built into Umbraco - what would be ideal would be to hook into the scope of that and add an event handler when the form is submitted, but I can't figure out how to access that and I suspect it may not be possible at all.

我可以通过插件在页面中使用我的 JavaScript,但我可以直接访问所涉及的表单元素,但我觉得这可能非常脆弱 - 特别容易受到 Umbraco 的影响更新 - 它通常与后台办公室的纹理背道而驰.

I have my JavaScript available in the page through a plugin but and I could access the form elements involved directly, but I feel as though that has the potential to be very fragile - particularly vulnerable to Umbraco updates - and it runs against the grain of the back-office in general.

Angular 或 Umbraco 是否提供了任何可以让我这样做的东西?如果没有,插入此行为的最实用方法是什么?

Is there anything made available by Angular or Umbraco which would allow me to do this? If not, what would be the most practical way to insert this behaviour?

推荐答案

正如你所说,做这种事情在更新过程中很容易出错.尽管使用 IContentService 事件不允许您显示模式客户端,但我建议您在应用程序启动期间查看在 IContentService.Saving 事件上注册偶数处理程序.

As you say doing this kind of thing is going to be prone to breaking during an update. Although using the IContentService events will not allow you to show a modal client side, I would recommend looking at registering an even handler on the IContentService.Saving event during the application startup.

public class ApplicationStartup : ApplicationEventHandler
{
    protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication,
        ApplicationContext applicationContext)
    {
        ContentService.Saving += ApplicationEvents.ContentService_Saving;

        base.ApplicationStarting(umbracoApplication, applicationContext);
    }

    internal static void ContentService_Saving(IContentService sender, SaveEventArgs<IContent> e)
    {
        if (e != null && e.SavedEntities.Any())
        {
            foreach (var entity in e.SavedEntities.Where(content=> content.ContentType.Alias == "something"))
            {


            }
        }
    }
}

这篇关于我可以使用 Angular 将客户端行为注入 Umbraco 7 后台吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆