main.html

by Sherali Turdiyev

HTML

<div ng-app="myApp">
    <div ng-controller="myCtrl">Strictly for Demo Purpose
        <div data-ng-view=""></div>
        <br />
        <button type="submit" ng-click="clear()">Clear</button>
    </div>
</div>

JavaScript

var myApp = angular.module('myApp', []);
myApp.factory('aProvider', function() {
   return {
            demotext: "sdf"
        }
});

myApp.config( function($routeProvider) {
     $routeProvider.when('/', {
        templateUrl: 'main.html',
         controller: 'viewCtrl'
    })
});
 
myApp.controller('myCtrl', function($scope,aProvider) {
    $scope.demotext = aProvider.demotext;
    $scope.clear = function () {
       aProvider.demotext = ""; // This is the place where I'm expecting solution
    }
});

 
myApp.controller('viewCtrl', function($scope,aProvider) {
    $scope.demotext = "df";
    
});