I have tried partial view with <ng-view>
directive I have used another controller in the partial view with controller script in the partial view file itself but it does not work it show error in console.
Below is the code
index.html
<!DOCTYPE html> <html> <head> <link data-require="[email protected]" data-semver="3.3.6" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.css" /> <script data-require="[email protected]" data-semver="1.5.8" src="https://code.angularjs.org/1.5.8/angular.js"></script> <script data-require="[email protected]" data-semver="1.5.8" src="https://code.angularjs.org/1.5.8/angular-route.js"></script> <link rel="stylesheet" href="style.css" /> <script> var testApp = angular.module("testApp", ["ngRoute"]).config(function ($routeProvider) { $routeProvider.when("/table", { templateUrl: "tab1.html" }); $routeProvider.when("/tab2", { templateUrl: "tab2.html" }); $routeProvider.when("/tab3", { templateUrl: "tab3.html" }); $routeProvider.when("/tab4", { templateUrl: "tab4.html" }); $routeProvider.otherwise({ templateUrl: "tab1.html" }); }); testApp.controller('testCtl',function($scope,$location){ $scope.check = function(selectedView){ return selectedView == $location.path(); } }); </script> </head> <body ng-app="testApp" ng-controller="testCtl"> <ul class="nav nav-tabs" style="margin-bottom: 15px;"> <li role="presentation" ng-class="{ active: check('/tab1')}"><a href="#/tab1">Tab ONE</a></li> <li role="presentation" ng-class="{ active: check('/tab2')}"><a href="#/tab2">Tab TWO</a></li> <li role="presentation" ng-class="{ active: check('/tab3')}"><a href="#/tab3">Tab THREE</a></li> <li role="presentation" ng-class="{ active: check('/tab4')}"><a href="#/tab4">Tab FOUR</a></li> </ul> <ng-view> </body> </html>
tab1.html
<script> angular.module("testApp").controller('tabOneCtl',function($scope){ $scope.meta = "something"; }); </script> <div ng-controller="tabOneCtl"> This is tab one and this tab has meta values which are shown below {{meta}} </div>
The meta is not binded instead I am getting an error in console.
Error: [ng:areq] Argument 'tabOneCtl' is not a function, got undefinedhttp://errors.angularjs.org/1.5.8/ng/ areq?p0=tabOneCtl&p1=not%20a%20function%2C%20got%20undefined
What am I doing wrong?
Here is the link to plunker