angularjs
factory to ctrl
HTML
<div ng-app="myApp">
<div ng-controller="testController">
<span>{{myText}}</span> <br/>
<button ng-click="test()">Start!!!</button>
</div>
</div>
JavaScript
var myApp = angular.module("myApp", []);
myApp.controller("testController", function($scope, myFactory) {
$scope.myText = "hello!";
$scope.test = function() {
myFactory.show($scope, function() {
});
}
});
myApp.factory("myFactory", function(mockDialog) {
function _show(scope, callback) {
mockDialog.popup({
scope: scope,
onTap: function(e) {
scope.myText = "it works! oui!!"; // not $scope
callback();
}
})
}
return {
show: _show
};
});
myApp.factory("mockDialog", function() {
function _popup(params) {
params && params.onTap && params.onTap();
}
return {
popup: _popup
}
});