0

I want to dynamically add menu JavaScript file and html to content.html, but it can't do.

I created simple example

demo

I try move "<script src="menu.js"></script>" to menu.html

4
  • did you even load angularjs library? Commented Jan 15, 2016 at 3:53
  • sure,it's part code. Commented Jan 15, 2016 at 3:57
  • It'd be good if you create a fiddle to show the problem. Commented Jan 15, 2016 at 4:08
  • You got to use router for that. You can either use ngRoute or uiRoute. I prefer uiRoute. Commented Jan 15, 2016 at 5:28

1 Answer 1

1

Your code moves away from the whole idea of writing single page app with angular. I have updated it to give you basic idea of how you would do the routes and share templates and use controller.

Check out the plunkr

html

<html>

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <link rel="stylesheet" href="menu.css" />
    <script data-require="[email protected]" src="https://code.angularjs.org/1.4.8/angular.js" data-semver="1.4.8"></script>
    <script data-require="ui-router@*" data-semver="0.2.15" src="https://cdn.rawgit.com/angular-ui/ui-router/805e69bae319e922e4d3265b7ef565058aaff850/release/angular-ui-router.js"></script>
    <script src="menu.js"></script>
    <script src="index.js"></script>
  </head>

  <body>
    <div id="menu" ng-include="'menu.html'"></div>
    <div ui-view></div>
  </body>

</html>

js

angular.element(document).ready(function() {
    angular.bootstrap(document, ["app"]);
});

angular.module('app',['moduleContent', 'moduleMenu', 'ui.router']);

var app = angular.module('app');

app.config(function($stateProvider) {
  $stateProvider
    .state('index', {
      url: "",
      templateUrl: "first.html",
      controller: 'firstCtrl'
    })
    .state('second', {
      url: "/second",
      templateUrl: "second.html"
    })
});

app.controller('firstCtrl', ['$scope', function($scope) {
  $scope.page = "first";
}]);

//Conttent module
angular.module('moduleContent',[])
.controller('contentCtrl', contentCtrl);

function contentCtrl(shareData)
{
    shareData.currentPage = 0;
}
Sign up to request clarification or add additional context in comments.

3 Comments

why I can't use multi page?
Why do you want to use multi page?
and template page own js css file belong itself

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.