简体   繁体   English

我可以使用Angular将客户端行为注入Umbraco 7后台吗?

[英]Can I inject a client-side behaviour into the Umbraco 7 back-office using Angular?

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. 我正在使用定制的Umbraco安装,并且遇到一种情况,当他们第一次单击带有某些类型内容的“发布”按钮时,我需要运行一些额外的用户交互。 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. 实际上,这将是弹出一个框,允许他们在将发布的内容共享给第三方服务时使用自定义消息。

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. 尽管我精通Java语言,但是我并没有花很多时间在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. 在这种情况下,编辑器使用Umbraco内置的标准Angular控制器-理想的情况是挂接到表单的范围并在提交表单时添加事件处理程序,但我不知道如何访问该表单,我怀疑这根本不可能。

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. 我可以通过插件在页面上使用我的JavaScript,但是我可以直接访问涉及的表单元素,但是我觉得这很有可能会变得非常脆弱-特别是受Umbraco更新的影响-并且它与后台一般。

Is there anything made available by Angular or Umbraco which would allow me to do this? Angular或Umbraco是否提供任何可以让我做到这一点的东西? If not, what would be the most practical way to insert this behaviour? 如果没有,插入此行为的最实用方法是什么?

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. 尽管使用IContentService事件将不允许您显示模式客户端,但我还是建议您在应用程序启动过程中在IContentService.Saving事件上注册一个偶数处理程序。

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"))
            {


            }
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Angular /客户端项目中使用转译为JavaScript的Kotlin代码 - Using Kotlin code transpiled to JavaScript in an Angular/client-side project 如何使用只读的HTML5验证字段客户端? - How can I validate a field client-side using HTML5 that is read only? 我可以使用/包含 HTML 部分,客户端,使用 EJS(或类似的)吗? - Can I use/include HTML partials, client-side, using EJS (or similar)? 如何使用ASP.NET添加客户端(JavaScript)确认消息框? - How can I add a client-side (JavaScript) confirmation message box using ASP.NET? 我可以使用客户端 Javascript 执行 DNS 查找(主机名到 IP 地址)吗? - Can I perform a DNS lookup (hostname to IP address) using client-side Javascript? 我可以使用HTML5发送客户端电子邮件吗? - Can I use HTML5 to send a client-side email? 如何通过全客户端实现来保护 Firebase? - How can I secure Firebase with an all client-side implementation? 我可以使用客户端脚本验证付费用户吗? - Can I verify paying users with a client-side script? 如何在客户端访问GridView的DataKey单元? - How can I reach DataKey cells of GridView on the client-side? 我可以将参数传递给客户端HTML页面吗? - Can I pass parameters to a client-side HTML page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM