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. android - 环信Easeui导入后启动报错UnsatisfiedLinkError2. linux - python ImportError: No module named ’***’3. javascript - vue.js插件中的全局方法,全局资源和实例方法区别是什么?4. php - msyql4字符5. javascript - ElementUI tree控件怎么通过子节点去找到父节点?6. python2.7 - python 函数或者类 代码的执行顺序7. 【小白问题】这行python命令行程序是什么意思?8. Mac怎么安装呢?9. python scrapy爬虫错误10. 为什么浏览器 运行不出来 ?是哪里出了问题呢?

网公网安备