Run Expression Trigger

On changing an answer, you may run an expression

                        function setCapitalAndCurrency(params) {
    if (params.length < 2) return;
    var country = params[0];
    var capitalQuestionName = params[1];
    var currencyQuestionName = params.length > 2 ? params[2] : null;
    var survey = this.survey;
    if (!country || !country.length) {
        survey.clearValue(capitalQuestionName);
        if (!!currencyQuestionName) {
            survey.clearValue(currencyQuestionName);
        }
        return;
    }
    survey.setVariable("request_processing", true);
    survey.setVariable("request_error", null);
    country = country.toLowerCase();
    $.ajax({
        url: "https://restcountries.eu/rest/v2/name/" + country,
        type: "GET",
        success: function (data) {
            if (!data || data.length < 1) return;
            var countryValue = data[0];
            survey.setValue(capitalQuestionName, countryValue.capital);
            var currencyValue = countryValue.currencies.length > 0 ? countryValue.currencies[0] : {};
            if (!!currencyQuestionName) {
                survey.setValue(currencyQuestionName, JSON.stringify(currencyValue));
            }
            survey.setVariable("request_processing", false);
        },
        error: function (xhr, ajaxOptions, thrownError) {
            survey.setVariable("request_error", "The country is not found.");
            survey.setVariable("request_processing", false);
            survey.clearValue(capitalQuestionName);
            if (!!currencyQuestionName) {
                survey.clearValue(currencyQuestionName);
            }
        }
    });
}
Survey.FunctionFactory.Instance.register("setCapitalAndCurrency", setCapitalAndCurrency);



var json = {
    questions: [
        { type: "text", name: "country", title: "Please enter the country" },
        { type: "html", name: "requesting", html: "The data is requesting", visibleIf: "{request_processing} = true" },
        { type: "text", name: "capital", title: "Capital of {country} is:", readOnly: true, visibleIf: "{capital} notempty" },
        { type: "text", name: "currency", title: "Currency in {country} is:", readOnly: true, visibleIf: "{currency} notempty" },
        { type: "html", name: "error", html: "The following error has happend: <b>{request_error}</b>", visibleIf: "{request_error} notempty" },
    ],
    triggers: [
        { type: "runexpression", expression: "{country} notempty or {country} empty", runExpression: "setCapitalAndCurrency({country}, 'capital', 'currency')" }
    ]
};

window.survey = new Survey.Model(json);


    survey.onComplete.add(function(result) {
        document.querySelector('#surveyResult').textContent =
            "Result JSON:\n" + JSON.stringify(result.data, null, 3);
    });


function onAngularComponentInit() {
    Survey.SurveyNG.render("surveyElement", { 
        model: survey 
    });
}
var HelloApp =
    ng.core
        .Component({
            selector: 'ng-app',
            template: '<div id="surveyContainer" class="survey-container contentcontainer codecontainer"><div id="surveyElement"></div></div> '})
        .Class({
            constructor: function() {
            },
            ngOnInit: function() {
                onAngularComponentInit();
            }
    });
document.addEventListener('DOMContentLoaded', function() {
    ng.platformBrowserDynamic.bootstrap(HelloApp);
});


                    
<!DOCTYPE html>
<html>
<head>
    <title>On changing an answer, you may run an expression, Angular2 Survey Library Example</title>


    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://unpkg.com/jquery"></script>
    <script src="https://npmcdn.com/zone.js@0.8.17/dist/zone.js"></script>
    <script src="https://npmcdn.com/core-js@2.6.5/client/shim.min.js"></script>
    <script src="https://npmcdn.com/rxjs@5.0.0-beta.6/bundles/Rx.umd.js"></script>
    <script src="https://npmcdn.com/@angular/core@2.0.0-rc.5/bundles/core.umd.js"></script>
    <script src="https://npmcdn.com/@angular/common@2.0.0-rc.5/bundles/common.umd.js"></script>
    <script src="https://npmcdn.com/@angular/compiler@2.0.0-rc.5/bundles/compiler.umd.js"></script>
    <script src="https://npmcdn.com/@angular/platform-browser@2.0.0-rc.5/bundles/platform-browser.umd.js"></script>
    <script src="https://npmcdn.com/@angular/platform-browser-dynamic@2.0.0-rc.5/bundles/platform-browser-dynamic.umd.js"></script>
<script src="https://surveyjs.azureedge.net/1.1.12/survey.angular.js"></script>
<link href="https://surveyjs.azureedge.net/1.1.12/survey.css" type="text/css" rel="stylesheet" />
    <link rel="stylesheet" href="./index.css">

</head>
<body>
            <ng-app></ng-app>
    <div id="surveyResult"></div>

<script type="text/javascript" src="./index.js"></script>

</body>
</html>