With a directive is quite simple:
<!DOCTYPE html>
<html data-ng-app="app">
<head>
<title>Upload</title>
</head>
<body>
<div id="putControllerHereWithoutDirective" data-mytest>
{{test}}
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js"></script>
<script>
'use strict';
angular.module('app',[])
.directive("mytest", function () {
return {
restrict: 'A',
controller: function ($scope) {
$scope.test = 'mytest';
},
link: function (scope, el, attrs) {
function test() {
alert('Clicked');
}
el.on('click', test);
}
};
});
</script>
</body>
</html>
with bind (cool :) )
<!DOCTYPE html>
<html data-ng-app="app">
<head>
<title>Upload</title>
</head>
<body>
<div id="putControllerHereWithoutDirective">
{{test}}
</div>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js"></script>
<script>
'use strict';
angular.module('app',[])
.run( function($rootScope) {
var returnFn = angular.bind($('#putControllerHereWithoutDirective'),function(){
this.attr('data-ng-controller','myCtrl');
}, []);
returnFn();
})
.controller('myCtrl',function($scope){
$scope.test = 'My test';
})
</script>
</body>
</html>
bindand also as adirective?