Hi I have a mvc application, with a home page and a partial view (Info.cshtml
) in that homepage. When I add an angularjs controller to the _Layout
(after: var myModule = angular.module("myModule", ["kendo.directives"]);)
and have in Info.cshtml
:
<div id="aaaa" ng-controller="test">{{msg}}</div>
<script>
///!!!!!!!!!!!!!IMPORTANT, do not remove!!!!!!!!!!!!!!
var $injector = angular.element($('#aaaa')).injector();
var element = angular.element($('#aaaa'));
$injector.invoke(function ($compile, $timeout) {
var scope = element.scope();
$compile(element)(scope);
$timeout(function () {
scope.$apply();
});
})
</script>
, everything is ok, but when I add the controller directly to the Info.cshtml
it breaks "Error: [ng:areq] Argument 'test' is not a function, got undefined"
:
<div id="aaaa" ng-controller="test">{{msg}}</div>
<script>
myModule.controller("test", function ($scope, $http, $timeout) {
alert('here');
$scope.msg = 'dsadsadaddas';
})
///!!!!!!!!!!!!!IMPORTANT, do not remove!!!!!!!!!!!!!!
var $injector = angular.element($('#aaaa')).injector();
var element = angular.element($('#aaaa'));
$injector.invoke(function ($compile, $timeout) {
var scope = element.scope();
$compile(element)(scope);
$timeout(function () {
scope.$apply();
});
})
</script>