AngularJS: Load view from Controller? -
i'd understand how load view controller ?
example, hypothetical:
myfile.html <p>{{foo}}</p> .controller("myctrl", function(){ $scope.html = loadfilehere("my foo", "myfile.html"); console.log($scope.html); }); i'd expect output: <p>my foo</p>
is possible ?
thanks!
i guessing talking loading partials? wouldn't load view controller, although maybe could...i use routes load view. controller return scoped data partial view , load ng-view div or whatever. example...
in app.js (or whatever call it) assuming myfile.html in same directory:
angular. module('app', []). config(['$routeprovider', function($routeprovider) { $routeprovider. when('/myfile', { templateurl: 'myfile.html', controller: myctrl }). otherwise({ redirectto: '/' }); }]);
then maybe in controllers.js file:
function myctrl($scope) { $scope.foo = "my foo"; }
and in myfile.html partial :
<p>{{foo}}</p>
and index.html file may like:
<!doctype html> <html ng-app="app"> <head> <script src="js/angular.min.js"></script> <script src="js/app.js"></script> <script src="js/controllers.js"></script> </head> <body> <div ng-controller="myctrl"> <div class="container"> <div ng-view></div> </div> <!-- /container --> </div> </body> </html>
Comments
Post a Comment