It is possible to do this if you don't mind using a bit of a hack to override the layer's createPopupTemplate method. If you replace the contents of the script tag starting on line 29 of the Intro to FeatureLayer Sample Sandbox with the code below, and click the Refresh button at the top right, you'll see it works as described:
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer",
"esri/core/reactiveUtils"
], (Map, MapView, FeatureLayer, reactiveUtils) => {
const map = new Map({
basemap: "hybrid"
});
const view = new MapView({
container: "viewDiv",
map: map,
popup: {
defaultPopupTemplateEnabled: true
},
extent: {
// autocasts as new Extent()
xmin: -9177811,
ymin: 4247000,
xmax: -9176791,
ymax: 4247784,
spatialReference: 102100
}
});
/********************
* Add feature layer
********************/
// Carbon storage of trees in Warren Wilson College.
const featureLayer = new FeatureLayer({
url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0"
});
featureLayer._esriCreatePopupTemplate = featureLayer.createPopupTemplate;
featureLayer.createPopupTemplate = function (options) {
var popupTemplate = this._esriCreatePopupTemplate(options);
popupTemplate.actions = [
{
title: "My Action",
id: "my-action",
className: "esri-icon-locate-circled"
}
];
return popupTemplate;
};
reactiveUtils.when(
() => view.popup?.actions,
() => {
view.popup.on("trigger-action", function (evt) {
alert(evt.action.title + " :: " + evt.action.id);
});
}
);
map.add(featureLayer);
});
The main part of this is seen on lines 36-48 above,