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. html5 - iframe src可以引入其他域名或者IP吧iframe src可以是其他域名过IP吧2. javascript - 给js写的盒子添加css样式,css样式没起作用。3. javascript - 如何将psd裁切下来的图片非常清晰的宣示出来4. javascript - vuex中action应该怎么分发事件5. html5 - 请问一下写H5的时候 你们都是兼容那些手机6. html5 - ElementUI table中el-table-column怎么设置百分比显示。7. mysqli函数8. web前端页面中实现表格效果,这个表格是可编辑的9. javascript - h5页面中iframe无法唤起iOS应用?10. 数据挖掘 - 如何用python实现《多社交网络的影响力最大化问题分析》中的算法?
![php-_server-php_self - nginx $_SERVER[’PHP_SELF’] 得到重复路径是什么原因?](http://www.haobala.com/attached/image/news/202309/1123091c0c.png)
网公网安备