javascript - Angular.js compile partial view controller -
hi have mvc application, home page , partial view (info.cshtml
) in homepage. when add angularjs controller _layout
(after: var mymodule = angular.module("mymodule", ["kendo.directives"]);)
, have in info.cshtml
:
<div id="aaaa" ng-controller="test">{{msg}}</div> <script> ///!!!!!!!!!!!!!important, 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>
, ok, when add controller directly info.cshtml
breaks "error: [ng:areq] argument 'test' not 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, 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>
Comments
Post a Comment