• 学习angularjs时遇到 XX is not a function


    出现这个问题是因为在 angularJs 1.3 中 为了让 根节点上(rootScope)不再被挂上许多冗余的内容,所以禁止了直接在根上注册controller。

    第一:以后不能直接以  function XXXcontroller (){ code......}这样的方式直接注册监听器了。以后必须

    angular.module('phonecatApp', []).controller('PhoneListCtrl',function($scope) {}这样来将controller注册到对应的模型上。

    第二:  在 ng-aap 中指定相对应的模型。

    如 之前:

    <html ng-app>(不指定则为根元素)

    现在:

    <html ng-app="phonecatApp">

    <DOCTYPE html>
    <html ng-app="HelloApp">
    <head>
    <title>test</title>
    <script src="../../angular.js"></script>
    </head>
    <body ng-controller="CartController">
    <h1>your Order</h1>
    <div ng-repeat='item in items'>
    <span>{{item.title}}</span>
    <input ng-model='item.quantity' >
    <span> {{item.price}} </span>
    <span>{{item.price*item.quantity}}</span>
    <button ng-click="remove($index)">Remove</button>
    </div>

    <script type="text/javascript">
    angular.module("HelloApp", []).controller("CartController", function($scope){
    $scope.items=[
    { title: 'paint pots', quantity: 8, price:3.95 },
    { title: 'polka dots', quantity: 17, price: 12.95},
    { title: 'Pebbles', quantity: 5, price: 6.95}
    ];

    $scope.remove = function(index){
    $scope.items.splice(index,1);
    }

    });




    </script>
    </body>
    </html>

  • 相关阅读:
    Scala学习(八)---Scala继承
    Scala学习(九)---文件和正则表达式
    Scala学习(六)---Scala对象
    jemter----命令行模式(cmd)导出测试报告
    js数据类型
    定期任务,如每月清理(SpringBoot Mybatis-Plus)
    定时执行任务(SpringBoot Mybatis-Plus)
    图片服务映射(SpringBoot mybatis-plus)
    图片压缩上传(Springboot mybatis-plus)
    java生成pdf
  • 原文地址:https://www.cnblogs.com/facial/p/4524847.html
Copyright © 2020-2023  润新知