Angular Js:简单的app无法正常工作

时间:2015-12-19 04:56:20

标签: javascript angularjs

我正在从codeSchool学习AngularJS,我正在制作一个简单的hello world应用程序,最初它正在被正确呈现但是过了一段时间它根本没有工作。我无法检测到这个bug,请帮忙 这是html文件的代码

var app = angular.module('store', []);

app.controller('StoreCtrl', ['$scope', function ($scope) {
    this.products = gems;
}])

gems = [{
    name: 'Dodecahedron',
    price: 2.95,
    description: 'This is the description of Dodecahedron'
    canPurchase: false;
},
{
    name:'Diamond',
    price: 5.95,
    description: 'Diamond is the most luxuriest gem of all.'
    canPurchase:true;
}]

app.controller('PanelCtrl', ['$scope', function ($scope) {
    this.tab=1;
    this.selectTab = function(setTab) {
        this.tab = setTab;
    };
    this.isSelectedTab = function(checkTab){
        return this.tab===checkTab;
    }

}])

appTest.js

root/
   angular.js
   appTest.js
   index.html

我的目录结构就像

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/list_swipe_refresh_layout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <GridView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:columnWidth="90dip"
            android:numColumns="auto_fit"
            android:verticalSpacing="1dp"
            android:horizontalSpacing="1dp"
            android:stretchMode="columnWidth"
            android:gravity="center"
            android:id="@+id/gridview"/>
        <ListView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:clickable="true"
            android:visibility="gone"
            android:id="@+id/listview"/>
    </android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>

这是带控制台的页面 jQuery ajax form submitting multiple times

3 个答案:

答案 0 :(得分:0)

你弄得双引号:

{{"Hello " + "World"}}

应该是:

app.get('*', function(req, res){
  res.sendFile(__dirname + '/public/index.html');
});

检查您的控制台是否有javascript错误。

答案 1 :(得分:0)

三个问题:

  • 修改下面的问候语

    {{&#34;你好&#34; +&#34;世界&#34;}}

在appTest.js中,

  • 在&#39; gem&#39;
  • 的描述字段后添加逗号
  • 删除&#34;;&#34; &#34; canPurchase&#34;
  • 之后的分号
你的html文件中的

  • 确保您包含&#34; appTest.js&#34;而不只是&#34; app.js&#34;

答案 2 :(得分:0)

appTest.js

var app = angular.module('store', []);

app.controller('StoreCtrl', function() {
    this.products = gems;
});

app.controller('PanelCtrl', function() {
    this.tab = 1;

    this.selectTab = function(setTab) {
        this.tab = setTab;
    };

    this.isSelected = function(checkTab) {
        return this.tab === checkTab;
    };
});

var gems = 
    [{
        name: 'Dodecahedron',
        price: 2.95,
        description: 'This is the description of Dodecahedron',
        canPurchase: false
    },
    {
        name: 'Diamond',
        price: 5.95,
        description: 'Diamond is the most luxuriest gem of all.',
        canPurchase: false
    }];

并在index.html中 {{"Hello" +"World"}}应为{{"Hello" + "World"}}

相关问题