angular.js - angular js配置路由 编写控制器的时候说跳转页内的数据模型不存在
问题描述
<!DOCTYPE html><html><head> <meta charset='UTF-8'> <title>angular admin test</title><link rel='stylesheet' href='http://apps.bdimg.com/libs/bootstrap/3.3.4/css/bootstrap.min.css'> <link rel='stylesheet' href='https://www.xxx.com/wenda/index.css'> <link rel='stylesheet' href='https://www.xxx.com/wenda/semantic.min.css'><!-- <base href='https://www.xxx.com/'>--></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 href='https://www.xxx.com/wenda/13933.html#/dashboard'> Dashboard</a> <a href='https://www.xxx.com/wenda/13933.html#/charts'> Charts</a> <a href='https://www.xxx.com/wenda/13933.html#/tables'> Tables</a> <a href='https://www.xxx.com/wenda/13933.html#/forms'> Forms</a> <a href='https://www.xxx.com/wenda/13933.html#/elements'> Bootstrap Elements</a> <a href='https://www.xxx.com/wenda/13933.html#/grid'> Bootstap Grid</a> <a href='https://www.xxx.com/wenda/13933.html#/components'> Component</a> <a href='https://www.xxx.com/wenda/13933.html#/menu'> Menu</a> <a href='https://www.xxx.com/wenda/13933.html#/blankpage'> 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. docker images显示的镜像过多,狗眼被亮瞎了,怎么办?2. 使用C#如何导入导出Excel文件?3. docker内创建jenkins访问另一个容器下的服务器问题4. javascript eval5. 关于docker下的nginx压力测试6. dockerfile - [docker build image失败- npm install]7. docker镜像push报错8. mysql - PHP如果不使用PDO,在构造SQL语句的时候,如何杜绝注入?9. 关于python切片的问题10. android-studio - android studio 结巴了,有什么办法可以治好它吗?