angular.js - angular controller-scope 的问题

浏览:27日期:2023-01-30

问题描述

下面这段代码:

<!DOCTYPE html><html><head lang='en'> <meta charset='UTF-8'> <title></title></head><body ng-app='app'><p ng-controller='MessageController'> {{message}}</p><script src='https://www.6hehe.com/angularv1.min.js'></script><script src='https://www.6hehe.com/wenda/message-controller-scope.js'></script></body></html>

/** * Created by Glacier on 2015/7/19.message-controller-scope.js */function MessageController($scope) { $scope.message = 'This is a model.';}

显示结果是{{message}};应该显示是This is a model.为什么显示不成功了?

问题解答

回答1:

孩子,你得angular对象都没有加载进去!!!

angular.module('app', []).controller('MessageController', function($scope){ $scope.message = 'This is a model.';});回答2:

我想,问题可能出在<script src='https://www.6hehe.com/angularv1.min.js'></script>这句,你看看路径是不是对的如果angularJS能够引入,那么针对ng-app='app'是可以自己扫描运行的,那么{{message}}你看到的就不是{{message}}了,要么是’This is a model.’,要么就是空白一片,要么就是console的报错.

相关文章: