search

Home  >  Q&A  >  body text

angular.js - angular controller-scope 的问题

下面这段代码:

<!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="../../angularv1.min.js"></script>
<script src="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.
为什么显示不成功了?

伊谢尔伦伊谢尔伦2744 days ago522

reply all(2)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-15 16:55:54

    Child, your angular objects are not loaded yet! ! !

    angular.module("app", []).controller("MessageController", function($scope){
         $scope.message = "This is a model.";
    });
    

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-15 16:55:54

    I think the problem may be
    <script src="../../angularv1.min.js"></script>
    This sentence, please check if the path is correct
    If angularJS can be introduced, then ng-app="app" can be scanned and run by itself. Then {{message}} what you see will not be {{message}}, or it will be 'This is a model.', Either it’s blank or there’s an error in the console.

    reply
    0
  • Cancelreply