JSFiddle - React, Tailwind, and code Playground

by Steven Lambert

HTML

<div ng-app="plunker">
    <div controller="myCtrl">
        <div>{{myVar}}</div>
        <br>
        <button ng-click="ngClickCall()">Call from ng-click</button>
        <button id="outside">Call from outside function</button>
    </div>
</div>

JavaScript

angular.module('plunker', []);

angular.module('plunker')
    .controller('myCtrl', function ($scope) {

    $scope.myVar = 'default val.'

    /**
     * Function may be called from Angular or from another source
     */
    $scope.myFunc = function myFunc(theVar) {
        // should I $apply or shouldn't I?
        $scope.myVar = theVar;
        console.log(theVar);
    }

    $scope.ngClickCall = function ngClickCall() {
        $scope.myFunc('ng-click call.');
    }

});

function outsideCall() {
    angular.element('article').scope().myFunc('outside call.');
}