So the title kinda says it all...
I want to use a materialize modal created by angular, only problem I got is it won't initialize correctly. Someone got a sollution?
The angular that gives me an object with values.
$http.get("../functions/getList.php")
.success(function (response) {
$scope.lists = response;
});
The HTML where I use the modal from materalizecss
<div id="modal1" class="modal">
<div class="modal-content">
<h4>Add Item to list: <!--list name hier--></h4>
<form>
<div class="row">
<div class="input-field col s12">
<label for="item-name">Item Name</label>
<input type="text" name="item-name" ng-model="itemName" id="item-name">
</div>
</div>
<div class="row">
<div class="input-field col s12">
<label for="item-description">Item Description</label>
<input type="text" name="item-description" ng-model="itemDescription" id="item-description">
</div>
</div>
</form>
</div>
<div class="modal-footer">
Add item
</div>
</div>
getList.php
$smt = $dbh->prepare("SELECT lists.name, lists.description, lists.deadline, lists.id FROM users INNER JOIN lists ON (users.id = lists.user_id) AND users.id = ?");
$smt->execute(array(
$user
));
$result = $smt->fetchAll(PDO::FETCH_ASSOC);
$json = json_encode($result);
print_r($json);
All you need to do is:
First:
Add this script to controller, to initialize materialize modal
$(document).ready(function(){
$('.modal').modal();
});
Example:
var myApp = angular.module('myApp',[]);
myApp.controller('TestController', ['$scope', function($scope) {
//initialize materialize modal
$(document).ready(function(){
$('.modal').modal();
});
}]);
Next: (Optional)
Use this line if you want to call the model programmatically
$('#modal1').modal('open'); //when you want to open modals programatically
Example:
$http.get("../functions/getList.php")
.success(function (response) {
$scope.lists = response;
$('#modal1').modal('open');
});
Next: (Optional)
Use "data-target" if you want to display modal on button click.. when using "ng-route" because href won't work because it will affect the ng-route and simply start redirecting pages
data-target="modal1" //instead of href="#modal1"
Example:
<button data-target="modal1" class="btn">Display My Modal</button>
Demo Here
var myApp = angular.module('myApp',[]);
var testController = function($scope, $http){
$(document).ready(function(){
$('.modal').modal();
});
$scope.clicked = function(){
$('#modal1').modal('open');
}
}
myApp.controller("testController",testController);
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script data-require="angular.js#~1.2.2" data-semver="1.2.28" src="https://code.angularjs.org/1.2.28/angular.js"></script>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.1/css/materialize.min.css">
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.1/js/materialize.min.js"></script>
<div ng-app ng-controller="testController">
<button data-target="modal1" class="btn">Click Me</button>
<button ng-click="clicked()" class="btn">ng-Click</button>
<div id="modal1" class="modal">
<div class="modal-content">
<h4>My Modal</h4>
</div>
<div class="modal-footer">
<a class=" modal-action modal-close waves-effect waves-green btn-flat" ng-click="createItem()">close</a>
</div>
</div>
</div>
Related
I added some ng-click events for buttons but when I try to click buttons, test() function won't fire. I did everything to fix that but I couldn't.
<div ng-controller="bilgiyarismasiCtrl" ng-repeat="x in sorular">
<div class="row text-center" style="margin: 50px 250px 50px 250px;">
<div class="col-md-12" style="padding:90px; background-color:gray; color:white;">
{{ x.SORU_ICERIGI }}
</div>
<div class="col-md-6" style="padding:50px; background-color:white;">
<button ng-click="test()" class="btn btn-primary btn-lg">{{ x.A_SIKKI }}</button>
</div>
<div class="col-md-6" style="padding:50px; background-color:white;">
<button ng-click="test()" class="btn btn-primary btn-lg">{{ x.B_SIKKI}}</button>
</div>
</div>
<br /><br /><br />
</div>
Angular code:
var app = angular.module("module", ["ngRoute"]);
app.config(function ($routeProvider) {
$routeProvider
.when("/", {
templateUrl: "bilgiyarismasi.html",
controller: "bilgiyarismasiCtrl"
});
});
app.controller("bilgiyarismasiCtrl", function ($scope, $http) {
$http.get("http://localhost:53438/api/BilgiYarismasi/GetSorular")
.then(function (response) {
$scope.sorular = response.data;
});
$scope.test = function () {
console.log(1)
}
});
FYI, Your code above is not invoking controller, due to this you are not able get output by clicking on any of your buttons.
Use below code :
var ngApp = angular.module('app', []);
ngApp.controller('bilgiyarismasiCtrl',function($scope, $http){
$scope.sorular = [];
/* $http.get("http://localhost:53438/api/BilgiYarismasi/GetSorular")
.then(function (response) {
$scope.sorular = response.data;
}); */
$scope.test = function () {
console.log('test')
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="app">
<div ng-controller="bilgiyarismasiCtrl">
<div >
<div class="row text-center" style="margin: 50px 250px 50px 250px;">
<div class="col-md-12" style="padding:90px; background-color:gray; color:white;">
{{ x.SORU_ICERIGI }}
</div>
<div class="col-md-6" style="padding:50px; background-color:white;">
<button ng-click="test()" class="btn btn-primary btn-lg">{{ 'x.A_SIKKI' }}</button>
</div>
<div class="col-md-6" style="padding:50px; background-color:white;">
<button ng-click="test()" class="btn btn-primary btn-lg">{{' x.B_SIKKI'}}</button>
</div>
</div>
<br /><br /><br />
</div>
</div>
</div>
You have not included ng-app in your template file.
I have created a demo, can you please have a look.
Hope this helps you.
I am new to Angular JS and I am using the 1.6 version of it.
I have this apptest.js script:
var myApp = angular.module("myApp", []);
(function(){
"use strict";
myApp.controller("productController", function($scope, $http)
{
$http.get('data/data.json').then(function(prd)
{
$scope.prd = prd.data;
});
});
});
And here my data/data.json data:
[
{
"id":"1",
"title":"20 Foot Equipment Trailer",
"description":"2013 rainbow trailer 20 feet x 82 inch deck area, two 5,000 lb axels, electric brakes, two pull out ramps, break away box, spare tire.",
"price":6000,
"posted":"2015-10-24",
"contact": {
"name":"John Doe",
"phone":"(555) 555-5555",
"email":"johndoe#gmail.com"
},
"categories":[
"Vehicles",
"Parts and Accessories"
],
"image": "http://www.louisianasportsman.com/classifieds/pics/p1358549934434943.jpg",
"views":213
}
]
Now here is my html page where I specified the ng-app and ng-controller:
<body ng-app="myApp" ng-controller="productController">
<div class="row">
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Add <span class="sr-only">(current)</span></li>
</ul>
<form class="navbar-form navbar-left">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<div class="col-sm-4" ng-repeat="product in prd">
<div class="panel panel-primary">
<div class="panel-heading">{{product.title}}</div>
<div class="panel-body">
<img ng-src="{{product.image}}">
{{product.price | currency}}
{{product.description}}
</div>
<div class="panel-footer">a</div>
</div>
</div>
</div>
<script src="angular/angular.js"></script>
<script src="scripts/appTest.js"></script>
</body>
I am still getting the following error which is new for me:
angular.js:14239 Error: [$controller:ctrlreg] The controller with the
name 'productController' is not registered.
http://errors.angularjs.org/1.6.0-rc.0/$controller/ctrlreg?p0=productController
Any help is appreciated.
Its because of your Immediately Invoked Function Expression. you have to change it like below :
var myApp = angular.module("myApp", []);
(function(app){
"use strict";
app.controller("productController", function($scope, $http){
$http.get('data/data.json').then(function(prd){
$scope.prd = prd.data;
});
});
})(myApp);
Just import the file in index.html,
<script src=".../productController.js"></script>
In my case, it was missing reference in index page as well as my controller name was startupController (notice lower case s) and I was trying to register it with StartupController (upper case s)
In my case, with this same error, I failed to identify the app module in the ng-app directive like this:
<div class="row" ng-app>
In some circumstances I've seen where ng-app is by itself but I was forced to identify the app like:
<div class="row" ng-app="myApp">
In My case, I just copied a piece of code from an example, and it contained another ng-app and ng-controller in one of its <DIV>. The message was initially confusing, as the required controller had the name Ctrl
If you are reading this, check the name of the controller not found on your web browser console. Mine was Ctrl
So, I realized that my structure had another controller named like this one:
Bad Code
<html ng-app="sampleApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
</head>
<body ng-controller="SampleCtrl">
<h1>{{message}}</h1>
<!-- SEE THIS TABLE HAS A CONTROLLER WITH A VERY UNDEFINED NAME, SO IT MAKES IT DIFFICULT TO TRACK -->
<table ng-app="app" ng-controller="Ctrl" >
<td>
<div>Select an image file: <input type="file" id="fileInput" /></div>
<div class="cropArea">
<ui-cropper image="myImage" area-type="rectangle" aspect-ratio="1.7" result-image="myCroppedImage" result-image-size='{w: 340,h: 200}' init-max-area="true">
</ui-cropper>
</div>
</td>
<td>
<div>Cropped Image:</div>
<div><img ng-src="{{myCroppedImage}}" /></div>
</td>
</table>
</body>
<script>
var myApp = angular.module("sampleApp", []);
myApp.controller("SampleCtrl", function ($scope) {
$scope.message = "It Works!";
});
</script>
SOLUTION
After removing the controller and app definition not initially desired, it worked like a charm.
<html ng-app="sampleApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
</head>
<body ng-controller="SampleCtrl">
<h1>{{message}}</h1>
<!-- SEE THE NOW DOES NOT HAVE A CONTROLLER, THE CONTROLLER WILL BE MY DEFAULT APP CONTROLLER SampleCtrl -->
<table>
<td>
<div>Select an image file: <input type="file" id="fileInput" /></div>
<div class="cropArea">
<ui-cropper image="myImage" area-type="rectangle" aspect-ratio="1.7" result-image="myCroppedImage" result-image-size='{w: 340,h: 200}' init-max-area="true">
</ui-cropper>
</div>
</td>
<td>
<div>Cropped Image:</div>
<div><img ng-src="{{myCroppedImage}}" /></div>
</td>
</table>
</body>
<script>
var myApp = angular.module("sampleApp", []);
myApp.controller("SampleCtrl", function ($scope) {
$scope.message = "It Works!";
});
</script>
I have the same problem.
I solved the problem by puting the js code in the main js.
my html is a layer on the main html
my original html and js are following :
<div style="background: #f5f5f5;" ng-app='myapp' ng-controller="cIdentityCtrl as ctrl">
<form class="padding-md" name="staffForm" ng-submit="submit()">
<div class="row popup" style="padding-bottom: 10px;" ng-repeat="item in sfList">
<label style="width: 130px;text-align: right;"> {{item.branchName}}:</label>
<input type="text" style="width: 175px;display: inline-block;" class="form-control" ng-model="item.PERCENT"
placeholder="股份比例">%
</div>
<div class="clearfix"></div>
<div class="height50"></div>
<div class="text-center iframe-layer-btn">
<button type="submit" class="btn btn-success" ng-disabled="staffForm.$invalid">保存</button>
<button type="button" class="btn btn-default" ng-click="close()">关闭</button>
</div>
</form>
</div>
<script>
var myapp= angular.module('myapp',[]);
(function(myapp){
"use strict";
myapp.service('layerService', layerService)
.factory('instance', instance);
myapp.controller('cIdentityCtrl', function($scope, instance, layerService) {
console.log(instance.storeList)
$scope.sfList = angular.copy(instance.storeList);
$scope.submit = function(){
for(var i=0;i<$scope.sfList.length;i++){
if($scope.sfList[i].PERCENT!=null && $scope.sfList[i].PERCENT!=''){
if(!/^(((\d|[1-9]\d)(\.\d{1,2})?)|100|100.0|100.00)$/.test($scope.sfList[i].PERCENT)){
massage.error($scope.sfList[i].branchName+'门店设置有误:[0,100]保留二位小数');
return false;
}
}
}
instance.fnsf($scope.sfList);
layerService.close(instance.layero1);
}
$scope.close=function(){
layerService.close(instance.layero1);
}
});
})(myapp);
</script>
this html and js opened by ng-include ,but can not find the controller . and I put the js in the parent html`s js file and it worked well.
I had same issue and found the reason as...
The app module in the ng-app directive was defined/used at body-tag level like this
<body ng-app="intervalAngularExample">
and the $controller definition in productionController.js was imported in the html file at header level, certainly that should not work.
<head>
<script src=".../productController.js"></script>
</head>
<body ng-app="intervalAngularExample">
</body>
import should be then inside the body tag.
This error occurs when the $controller() service is called with a string that does not match any of the registered controllers. The controller service may have been invoked directly, or indirectly, for example through the ngController directive, or inside a component / directive / route definition (when using a string for the controller property). Third-party modules can also instantiate controllers with the $controller() service
Causes for this error can be:
1- Your reference to the controller has a typo. For example, in the ngController directive attribute, in a component definition's controller property, or in the call to $controller().
2- You have not registered the controller (neither via Module.controller nor $controllerProvider.register().
3- You have a typo in the registered controller name.
ref: https://docs.angularjs.org/error/$controller/ctrlreg?p0=GreetingController
Here's the code snippet of the Angular js app.
var app = angular.module("list", []);
app.controller("myctrl", function($scope) {
$scope.get = function() {
$scope.thiss = false;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="list" ng-init="thiss = true">
<p ng-controller="myctrl">
<button ng-click="get()">Click</button>
<p ng-show="thiss">This is it</p>
</p>
</div>
i have been learning AngularJS. I cannot understand why this simple example fails to work. I have been followng w3cschools tutorial and the syntax seem to perfect align with it. Is it something to with scoping ? or do i have to bind ng-show with model data.
I also did the following but it doesnot seem to work.
<div ng-app="list" ng-init="thiss = true">
<p ng-controller="myctrl" >
<button ng-click="thiss=false">Click</button>
<p ng-show="thiss"> This is it</p>
</p>
</div>
Why is placing the controller on the div tag works ? But fails to work when it is in the child element?
It does not work because you have a <p> tag within a <p> tag. It should work if you change you code as follows.
<div ng-controller="myctrl" >
<button ng-click="thiss=false">Click</button>
<p ng-show="thiss"> This is it</p>
</div>
var app = angular.module("list", []);
app.controller("myctrl", function($scope) {
$scope.get = function() {
$scope.thiss = false;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="list" ng-init="thiss = true">
<div ng-controller="myctrl">
<button ng-click="get()">Click</button>
<p ng-show="thiss">This is it</p>
</div>
</div>
Check out Why <p> tag can't contain <div> tag inside it? for the reason why <p> cannot include block level elements
Please, don't try to make your HTML standard, follow some rule defined by HTML.
Don't put nested <p> tags. AngularJS sometimes don't work for invalid DOM. I used <span> tag instead of nested <p> works fine.
var app = angular.module("list", []);
app.controller("myctrl", function($scope) {
$scope.get = function() {
$scope.thiss = false;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="list" ng-init="thiss = true">
<p ng-controller="myctrl">
<button ng-click="get()">Click</button>
<span ng-show="thiss">This is it</span>
</p>
</div>
For more information validate HTML. Please, check following HTML code at: https://validator.w3.org/#validate_by_input
<!doctype html>
<html>
<head>
<title>Test</title>
</head>
<body>
<p>
<p>
</p>
</p>
</body>
</html>
Try this. I have just remove ng-controller from <p> and put it inside div with ng-app. don't know the reason behind this behavior of angularjs but it works as you want.
var app = angular.module("list", []);
app.controller("myctrl", function($scope) {
$scope.get = function() {
$scope.thiss = false;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="list" ng-init="thiss = true" ng-controller="myctrl">
<p>
<button ng-click="get()">Click</button>
<p ng-show="thiss">This is it</p>
</p>
</div>
Try following code.
var app=angular.module("list",[]);
app.controller("myctrl",function($scope){
$scope.get=function(){
$scope.thiss = false;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="list" ng-controller="myctrl">
<p ng-init="thiss=true">
<button ng-click="get()">Click</button>
{{thiss}}
<p ng-show="thiss">Show Content</p>
<p ng-show="!thiss">Hidden Content</p>
</p>
</div>
try after removing the blank array from the dependency
var app = angular.module('list');
make sure that the controller should be placed in <div ng-controller="myctrl">
Your code:
<p ng-controller="myctrl">
<button ng-click="get()">Click</button>
<p ng-show="thiss">This is it</p>
</p>
this is how a browser interprets html according to DOM :
<p ng-controller="myctrl">
<button ng-click="get()">Click</button>
</p>
<p ng-show="thiss">This is it</p>
<p></p>
therefore the scope of your controller "myctrl" does not apply on nested para,
try using div instead of nested <p>
var app = angular.module("list", []);
app.controller("myctrl", function($scope) {
$scope.get = function() {
$scope.thiss = false;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="list" ng-init="thiss = true">
<div ng-controller="myctrl">
<button ng-click="get()">Click</button>
<p ng-show="thiss">This is it</p>
</div>
</div>
I've been trying unsuccessfully for the past hour to get the list of objects declared in my angularJS controller to populate the dropdown menu. When I click on an object in the dropdown list I want the controller to then call on the factory called "API" which then returns the html page that corresponds with the object selected.
HTML
<html ng-app="app">
<head>
<link rel="stylesheet" href="css/bootstrap.min.css" />
</head>
<nav class="navbar navbar-default">
<div class="container"> <!-- top intro part -->
<div class="navbar-header">
<a class="navbar-brand" href="#/"> OPENCV 3.0.0</a>
</div>
<ul class="nav navbar-nav navbar-right">
<li><i class="fa fa-home"></i> Home</li>
<li><i class="fa fa-shield"></i> About</li>
<li><i class="fa fa-comment"></i> Contact</li>
</ul>
</div>
</nav>
<body ng-controller="MainController">
<div class="row">
<div class="col-md-10"> <!-- opencv dropdown menu -->
<div id="opencvFilters">
<form class="form-horizontal" role="form">
<label class="control-label col-md-2">Opencv Filters :</label>
<div class="col-md-10">
<select class="form-control"
ng-model="template"
ng-options="t.name for t in templates">
<!--ng-change="Opencv_Controllers(filter)">-->
<option value=""> Select Filter</option>
</select>
</div>
</form>
</div>
</div>
</div>
<div ng-include="template.url"><div>
<script src="js/angular.min.js"></script>
<script src="js/ui-bootstrap-tpls-0.14.3.min.js"></script>
<script src="js/app.js"></script>
</body>
</html>
angularJS
var app = angular.module("app", ["ui.bootstrap"]);
//http://stackoverflow.com/questions/18571001/file-upload-using-angularjs
app.factory("API", function ($http) {
return {
uploadImage: function (image) {
$http.post("upload.php", image);
}
}
)};
app.controller("MainController", ["$scope, API", function($scope, API) {
$scope.imageUrl = "";
$scope.template = "";
$scope.templates = []; // Declare Array
$scope.templates.push("MakeGray"); // Push object into array
$scope.templates.push("Canny");
$scope.template = $scope.templates[0];
$scope.add = function() {
var f = document.getElementById('file').files[0];
var r = new FileReader();
r.onloadend = function(e) {
var data = e.target.result;
API.uploadImage(data)
.success(function (imgUrl) {
$scope.imageUrl = imgUrl;
})
.error (function (error) {
});
}
r.readAsBinaryString(f);
}
}]);
EDIT: Correct answer :
Try using ng-options="t for t in templates" instead of "t.name". You haven't assigned a "name" property to that json object
I have layout page, in Layout render one HTML page, in that HTML page contains dropdown button display list of studentnames. My Code is
var MainCtrl;
MainCtrl = [
'$scope', '$state', '$stateParams', 'dataFactory', 'cacheKeys', '$rootScope', '$window', '$document', "$q", function ($scope, $state, $stateParams, dataFactory, cacheKeys, $rootScope, $window, $document, $q) {
"use strict";
$scope.isLoad = false;
$scope.students = [];
$scope.currentAppId = null;
$scope.loadStudents = function () {
var deferred = $q.defer();
dataFactory.get("Student/All")
.then(function (result) {
$scope.students = result.data.data;
$scope.currentStudentName = $scope.students[0].name;
deferred.resolve($scope.students);
if ($scope.students.length === 0) {
$window.location.href = '/Account/WelCome';
}
else {
$scope.isLoad = true;
}
});
return deferred.promise;
};
$scope.loadStudents();
}
];
var AppSettingCtrl;
AppSettingCtrl = [
'$scope', '$state', '$stateParams', function ($scope, $state, $stateParams) {
"use strict";
if (!_.isEmpty($stateParams.stdId))
{
$scope.selectedStudentData = _.findWhere($scope.students, { "id": $stateParams.stdId });
$scope.currentStudentName = $scope.selectedStudentData.name;
}
$scope.currentStudentId = $stateParams.stdId;
if (_.isEmpty($scope.currentStudentId) && $scope.students.length > 0)
{
$scope.appTabs.closeCurrentTab();
$state.go($state.current.name, { appId: $scope.students[0].id });
}
$scope.gotoApp = function (stdId) {
if (_.isEmpty(stdId)) {
return;
}
$state.go($state.current.name, {stdId: stdId});
};
}
];
app.controller('AppSettingCtrl', AppSettingCtrl);
app.controller('MainCtrl', MainCtrl);
<!DOCTYPE html>
<html ng-app="app">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>STUDENT</title>
</head>
<body ng-controller="BaseCtrl">
<!-- Content Start-->
<div ng-controller="ConstantCtrl">
<div id="main-container" ng-controller="MainCtrl" class="container-fluid">
<div ng-controller="AppSettingCtrl">
#RenderPage("_TopNavBar.cshtml")
</div>
<!-- Left Bar Start-->
<div id="left-bar" style="left: {{navButton.leftBarLeft}}">
<div class="left_bG"></div>
<!-- Toggle Btn Start-->
<span>
<a href="/Home/Dashboard" class="navbar-brand">
<img src="~/Content/images/logo.png" />
</a>
</span>
<a id="anchor_btn" href="javascript:void(0)" ng-click="anchorClicked()" ng-class="navButton.class"></a>
<!-- Toggle Btn End-->
<!-- Sidebar Navigation Start-->
#*#{Html.RenderPartial("_LeftNavigationPartial");}*#
#RenderPage("_LeftNavigationPartial.cshtml")
</div>
<!-- Left Bar End-->
<!-- Right Bar Start-->
<div id="right-bar" style="margin-left: {{navButton.rightBarLeft}}">
#*#{Html.RenderPartial("_RightBarPartial");}*#
#RenderPage("_RightBarPartial.cshtml")
#RenderBody()
</div>
<!-- Right Bar End-->
</div>
</div>
</div><!-- Content End-->
</body>
</html>
_TopNavBar.cshtml:-
<!-- Wrapper Start-->
<nav role="navigation" class="navbar navbar-default top-bar">
<div class="col-xs-5 col-sm-3 col-lg-5 mar0 pad0 pull-right">
<div class="col-xs-12 col-sm-2 col-lg-8 itemsdropdown mar0 pull-right tabbg">
<div class="btn-group student-panel">
<div class="btn-group" dropdown is-open="status.isopen">
<p>Current Student</p>
<button type="button" aria-expanded="false" class="btn btn-default dropdown-toggle" dropdown-toggle ng-disabled="disabled">
{{currentStudentName}} <span class="fa fa-angle-down"></span>
</button>
<ul class="dropdown-menu" role="menu" ng-model="currentAppId">
<li ng-repeat="student in students" ng-click="gotoApp(student.id)"><a>{{student.name}}</a></li>
</ul>
</div>
</div>
</div>
</div>
<button id="btnLogout" class="btn btn-primary btn-sm pull-right" onclick="location.href='#Url.Action("SignOff", "Account")'">Log Out</button>
<section class="container-fluid header">
<div class="navbar-header col-md-2 main-logo">
<span>
<a href="/Home/Dashboard" class="navbar-brand admin-logo">
<img src="~/Content/images/small-logo.png" alt="logo">
</a>
</span>
</div>
</section>
</nav>
<!-- Wrapper End-->
In the above code render topnavbar HTML in layout, first run the application main controller called get studets list and select first student name assign to scope.currentStudentName. Next user click the dropdown button and select one student control goes to appsetting controller getv student name and bind to scope variable but that name not display on dropdown. Now I want to display selected name in dropdown using AngularJS.
After doing some modifications on this, Eventually i got the solution
Move gotoApp function from AppSettingCtrl to MainCtrl Like
MainCtrl:-
$scope.gotoApp = function (stdId) {
if (_.isEmpty(stdId)) {
return;
}
if (!_.isEmpty(stdId)) {
$scope.selectedStudentData = _.findWhere($scope.students, { "id": stdId });
$scope.currentStudentName = $scope.selectedStudentData.name;
$state.go($state.current.name, { stdId: stdId });
}
};