angular.js - angular js配置路由 編寫控制器的時候說跳轉頁內的數據模型不存在
問題描述
<!DOCTYPE html><html><head> <meta charset='UTF-8'> <title>angular admin test</title><link rel='stylesheet' > <link rel='stylesheet' > <link rel='stylesheet' ><!-- <base >--></head><body ng-app='myapp'> <body ng-app='myapp'><p ng-app='admin'><p><p> <span>Admin angular</span></p><p> <!--<a>Download Now</a>--> <button class='btn-download ui inverted basic button'>Download Now</butto></p></p><p><p class='ui inverted vertical menu'> <a > Dashboard</a> <a > Charts</a> <a > Tables</a> <a > Forms</a> <a > Bootstrap Elements</a> <a > Bootstap Grid</a> <a > Component</a> <a > Menu</a> <a > BlankPage</a></p> </p> <p ng-view></p></p> </body></html>
app.js配置路由的
var app = angular.module(’myapp’, [’ngRoute’, ’ngAnimate’])//app.value(’defaultcount’, 100)app.config(function ($routeProvider) { // $locationProvider.html5Mode(true) $routeProvider.when(’/dashboard’, { templateUrl: ’dashboard.html’, controller: ’dashboard’, authenticate: true})// $routeProvider.when(’/charts’, {//templateUrl: ’charts.html’,// })// $routeProvider.when(’/tables’, {//templateUrl: ’tables.html’,// })// $routeProvider.when(’/forms’, {//templateUrl: ’forms.html’,// })})app.controller(’dashboard’, function ($scope) { $scope.save = function () {alert(’success’) } $scope.reset = function () {$scope.notecontent = '' } $scope.count = 100 - $scope.notecontent.length;})
出錯如下angular.js - angular js配置路由 編寫控制器的時候說跳轉頁內的數據模型不存在
angular.js - angular js配置路由 編寫控制器的時候說跳轉頁內的數據模型不存在
求大神帶!!!!!!
問題解答
回答1:
$scope.notecontent是全局變量,但是在使用之前也是要聲明的。這個變量在你點擊重置按鈕之前還沒有被定義,雖然你點擊之后定義的是全局變量。可以在controller頂部聲明一次$scope.notecontent=’’;就行了。
還有個問題,你這代碼里有三個ng-app居然運行成功了。。。
相關文章:
1. python - 數據與循環次數對應不上2. mysql - 把一個表中的數據count更新到另一個表里?3. 請教使用PDO連接MSSQL數據庫插入是亂碼問題?4. mysql - 分庫分表、分區、讀寫分離 這些都是用在什么場景下 ,會帶來哪些效率或者其他方面的好處5. Python爬蟲如何爬取span和span中間的內容并分別存入字典里?6. 視頻文件不能播放,怎么辦?7. mysql 查詢身份證號字段值有效的數據8. python - 爬蟲模擬登錄后,爬取csdn后臺文章列表遇到的問題9. node.js - nodejs開發中常用的連接mysql的庫10. 黑客 - Python模塊安全權限
